CSH 6.4 Conditional Statements MrG 2013.0213

2978 days ago by CSH2012

#1) (n>0 and n%2==0) 
       
#2) not(x>=-1 and x<=1) #2) (x<-1 or x>1) 
       
#3) not(a or (not b)) #3) not a and b 
       
#4) return num days in a month def numDays(month): if month=='jan': return 31 elif month=='feb': return 28 elif month=='mar': return 31 elif month=='apr': return 30 elif month=='may': return 31 elif month=='jun': return 30 elif month=='jul': return 31 elif month=='aug': return 31 elif month=='sep': return 30 elif month=='oct': return 31 elif month=='nov': return 30 elif month=='dec': return 31 numDays('oct') 
       
31
31
#5) def isLeapYear(y): return y%4==0 and (y%100!=0 or y%400==0) for y in range(2000,2013,1): if isLeapYear(y): print y 
       
2000
2004
2008
2012
2000
2004
2008
2012
#6) def isPrime(n): if n<2: return false if n==2: return true if n%2==0: return false count=0 for d in range(n): if n%(d+1)==0: count=count+1 return count==2 for n in range(1000): if isPrime(n): print n 
       
WARNING: Output truncated!  
full_output.txt



2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
211
223
227
229
233
239
241
251
257
263
269
271
277

...

599
601
607
613
617
619
631
641
643
647
653
659
661
673
677
683
691
701
709
719
727
733
739
743
751
757
761
769
773
787
797
809
811
821
823
827
829
839
853
857
859
863
877
881
883
887
907
911
919
929
937
941
947
953
967
971
977
983
991
997
WARNING: Output truncated!  
full_output.txt



2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
211
223
227
229
233
239
241
251
257
263
269
271
277

...

599
601
607
613
617
619
631
641
643
647
653
659
661
673
677
683
691
701
709
719
727
733
739
743
751
757
761
769
773
787
797
809
811
821
823
827
829
839
853
857
859
863
877
881
883
887
907
911
919
929
937
941
947
953
967
971
977
983
991
997
#10) h='' while(h!='q'): c=choice(['r','p','s']) h=choice(['r','p','s','q']) if(c=='r' and h=='r'): print "tie" if(c=='r' and h=='p'): print "human wins!" if(c=='r' and h=='s'): print "computer wins!" if(c=='p' and h=='r'): print "computer wins!" if(c=='p' and h=='p'): print "tie!" if(c=='p' and h=='s'): print "human wins!" if(c=='s' and h=='r'): print "human wins" if(c=='s' and h=='p'): print "computer wins!" if(c=='s' and h=='s'): print "tie!" 
       
tie!
human wins!
human wins
tie!
tie!
tie
human wins!
computer wins!
human wins
human wins!
computer wins!
human wins!
computer wins!
computer wins!
tie!
human wins!
human wins
tie!
tie!
tie
human wins!
computer wins!
human wins
human wins!
computer wins!
human wins!
computer wins!
computer wins!