File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """IF statement
2+
3+ There can be zero or more elif parts, and the else part is optional. The keyword ‘elif’ is
4+ short for ‘else if’, and is useful to avoid excessive indentation.
5+
6+ An if … elif … elif … sequence is a substitute for the switch or case statements found
7+ in other languages.
8+ """
9+
10+ number = 15
11+ conclusion = ''
12+
13+ if number < 0 :
14+ conclusion = 'Number is less than zero'
15+ elif number == 0 :
16+ conclusion = 'Number equals to zero'
17+ elif number < 1 :
18+ conclusion = 'Number is greater than zero but less than one'
19+ else :
20+ conclusion = 'Number bigger than or equal to one'
21+ assert conclusion == 'Number bigger than or equal to one'
Original file line number Diff line number Diff line change 1+ #ask the user to enter marks and save in variable 'marks'
2+ marks = int (input ("Please Enter The Marks" ))
3+ #check if the marks is btwn 0 to 20
4+ if marks >= 0 and marks < 20 :
5+ print ("FAIL" )
6+ elif marks >= 20 and marks < 40 :
7+ print ("PASS" )
8+ elif marks >= 40 and marks < 60 :
9+ print ("GOOD" )
10+ elif marks >= 60 and marks < 80 :
11+ print ("V.GOOD" )
12+ elif marks >= 80 and marks <= 100 :
13+ print ("EXCELLENT" )
14+ else :
15+ print ("Incorrect value" )
Original file line number Diff line number Diff line change 1+ #logics > < == <= >=
2+ password = input ("Please Enter Your Password :" )
3+ if password == "sony321" :
4+ print ("Successfully Logged in! ;) " )
5+ else :
6+ print ("Incorrect password! Please Try again!" )
Original file line number Diff line number Diff line change 11#intergers
2- positiveInteger = 30
2+ positiveInteger = 50
33negativeInteger = - 20
4- #float
4+ x = 300
5+ y = 89
6+ abdirahman = 40
7+
8+ #float --> numbers with decimals
59floatNumber = 3.5
610floatNegative = - 9.1
7- #scientific numbers
8- standanrdForm = 3e4
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+ answer = floatNegative / floatNumber
21+ #print(answer*10)
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+ #scientific numbers ->numbers in standard form
33+ standardForm = 3e14
34+ print (standardForm )
935#boolean
1036trueBoolean = True
1137falseBoolean = False
38+
39+
40+
41+
42+
43+
44+
45+
46+ #when school starts
47+ breakTime = False
48+ time = 0
49+ ########################
50+ if time == 945 :
51+ breakTime = True
52+ print ("everyone eats ;) " )
53+
54+
55+
56+
57+
58+
59+
60+
1261#complex numbers
1362complexNumber1 = 3 + 10j
1463complexNumber2 = 6 - 10j
1564
16- print (complexNumber1 * complexNumber2 )
Original file line number Diff line number Diff line change 1+ #rock paper scissors
2+ import random
3+ Rock = 1
4+ Paper = 2
5+ Scissors = 3
6+ gameOver = False
7+ print ("Game ON!" )
8+ while gameOver == False :
9+ #your choice
10+ player1 = int (input ("1 for Rock, 2 for Paper, 3 for Scissors :" ))
11+ #the computer choice
12+ player2 = random .randint (1 ,3 )
13+ if (player2 == 1 ):
14+ choiceComputer = "Rock"
15+ elif (player2 == 2 ):
16+ choiceComputer = "Paper"
17+ elif (player2 == 3 ):
18+ choiceComputer = "Scissors"
19+ #the player choice
20+ if (player1 == 1 ):
21+ choicePlayer = "Rock"
22+ elif (player1 == 2 ):
23+ choicePlayer = "Paper"
24+ elif (player1 == 3 ):
25+ choicePlayer = "Scissors"
26+ #lets check who wins
27+ if (player1 == 1 and player2 == 1 ) or (player2 == 2 and player1 == 2 ) or (player1 == 3 and player2 == 3 ) or (player1 == 1 and player2 == 2 ):
28+ print ("The computer chose: " + choiceComputer + " And you chose: " + choicePlayer )
29+ print ("you thought you would win!! its a draw:" )
30+ elif (player1 == 3 and player2 == 2 ) or (player2 == 1 and player1 == 2 ) or (player1 == 3 and player2 == 3 ) or (player1 == 2 and player2 == 3 ):
31+ print ("Computer won!! you loose!" )
32+ print ("The computer chose: " + choiceComputer + " And you chose: " + choicePlayer )
33+ else :
34+ print ("You won!!! " )
35+ print ("The computer chose: " + choiceComputer + " And you chose: " + choicePlayer )
36+ keepOn = int (input ("Do you want to try again ? (1=yes && 2=no ) :" ))
37+ if keepOn == 2 :
38+ gameOver = True
You can’t perform that action at this time.
0 commit comments