Skip to content

Commit 31b64de

Browse files
committed
python activities sem 1
1 parent 25c5e13 commit 31b64de

5 files changed

Lines changed: 133 additions & 5 deletions

File tree

ControlFlow/if_example.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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'

DataTypes/GradeSystem.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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")

DataTypes/loops.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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!")

DataTypes/numbers.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,64 @@
11
#intergers
2-
positiveInteger=30
2+
positiveInteger=50
33
negativeInteger=-20
4-
#float
4+
x=300
5+
y=89
6+
abdirahman=40
7+
8+
#float --> numbers with decimals
59
floatNumber=3.5
610
floatNegative=-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
1036
trueBoolean=True
1137
falseBoolean=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
1362
complexNumber1=3+10j
1463
complexNumber2=6-10j
1564

16-
print(complexNumber1*complexNumber2)

Y9 Sem 1/Rock_Sciccors_Paper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

0 commit comments

Comments
 (0)