0% found this document useful (0 votes)
62 views8 pages

Python Ad

The document provides code snippets and outputs for several Python programs, including: 1) A print statement that takes user input for a name and prints a greeting 2) A program that checks if a number is odd or even 3) A program that determines a student's grade based on average marks 4) A program that finds the largest of three numbers 5) A program that performs basic math operations on two numbers

Uploaded by

Akash Rao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views8 pages

Python Ad

The document provides code snippets and outputs for several Python programs, including: 1) A print statement that takes user input for a name and prints a greeting 2) A program that checks if a number is odd or even 3) A program that determines a student's grade based on average marks 4) A program that finds the largest of three numbers 5) A program that performs basic math operations on two numbers

Uploaded by

Akash Rao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Instructions:

1) To create directory type mkdir <directory


name>
2) To change the directory: cd <directory
name>
3) To check current directory type: Pwd
(present working directory)
4) To goback to previous directory type: cd . .
5) To start python in terminal type: python3
6) To close python editor type: exit( )
7) To open/create a text file: gedit
<filename>.txt
8) To clear everything on terminal type: clear
9) To open sublime text type: subl
10) To run a program type: python3
<filename>.py

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:

Enter marks of the first subject: 89


Enter marks of the second subject: 95
The student has obtained 'A' Grade

Largest of three numbers:

4|Page
Code:
num1 = int(input("Enter the first number-"))
num2 = int(input("Enter the second number-"))
num3 = int(input("Enter the third number-"))

if(num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The Largest Number Between",num1,",",num2,"and",num3,"is-",largest)

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)

print("Addition of the numbers is: ",i)


print("Subtraction of the numbers is: ",p)
print("Multiplication of the numbers is: ",l)
print("Divition of the numbers is: ",k)

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

You might also like