Python Ad
Python Ad
1|Page
Print Statement:
Code:
i = input("Hi!! Enter your name: ")
print("Hii", i,"nice to meet you")
Output:
Hi!! Enter your name: Akash
Hii Akash nice to meet you
2|Page
Check whether the number is odd or
even:
Code:
i = int(input("Enter a number: "))
if i % 2 == 0:
print("The number is Even!")
else:
print("The number is Odd!")
Output:
Enter a number: 5
The number is Odd!
Enter a number: 4
The number is Even!
3|Page
Grade obtained by student:
Code:
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
avg=int(sub1+sub2)/2
if(avg >= 90):
print("The student ha obtained 'A' Grade")
elif(avg >= 80 & avg < 90):
print("The student ha obtained 'B' Grade")
elif(avg >= 70 & avg < 80):
print("The student ha obtained 'C' Grade")
elif(avg >= 60 & avg < 70):
print("The student ha obtained 'D' Grade")
else:
print("The student ha obtained 'E' Grade; Fail!!" )
Output:
4|Page
Code:
num1 = int(input("Enter the first number-"))
num2 = int(input("Enter the second number-"))
num3 = int(input("Enter the third number-"))
Output:
Enter the first number-2
Enter the second number-6
Enter the third number-4
The Largest Number Between 2 , 6 and 4 is- 6
5|Page
Addition, subtraction, multiplication
and division of two numbers:
Code:
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
i = int(a+b)
p = int(a-b)
l = int(a*b)
k = int(a/b)
Output:
Enter the first number: 12
Enter the second number: 10
Addition of the number is: 22
Subtraction of the number is: 2
Multiplication of the number is: 120
Division of the number is: 1.2
6|Page
Even and odd numbers between 0 to 100:
Code:
o=0
e=0
for x in range(0,101):
if (x % 2 == 0):
e=e+1
else:
o=o+1
print("The number of even numbers is: ",e)
print("The number of odd numbers is: ",o)
Output:
The number of even numbers is: 50
The number of odd numbers is: 50
7|Page
Dies:
Code:
for i in range(1,7):
r = input("WELCOME TO SNAKE AND LADDER GAME, PRESS R
TO ROLL, E TO EXIT: ")
if r == 'R':
if i ==1 or i == 3 or i == 4:
print("YOU GOT", 6)
elif i == 2 or i == 5:
print("YOU GOT:", 2)
else:
print("YOU GOT:", 3)
elif r == 'E'
print("THANK U FOR PLAYING THE GAME!!")
exit()
print("YEAH!!, U WON!!")
Output:
WELCOME TO SNAKE AND LADDER GAME, PRESS R TO ROLL, E TO EXIT: R
YOU GOT: 2
WELCOME TO SNAKE AND LADDER GAME, PRESS R TO ROLL, E TO EXIT: R
YOU GOT 6
WELCOME TO SNAKE AND LADDER GAME, PRESS R TO ROLL, E TO EXIT: R
YOU GOT 6
WELCOME TO SNAKE AND LADDER GAME, PRESS R TO ROLL, E TO EXIT: E
THANK U FOR PLAYING THE GAME!!
8|Page