0% found this document useful (0 votes)
22 views

Python Doc (Input and Output)

The document contains 17 code snippets that demonstrate various Python programming concepts like data types, conditional statements, loops, functions and turtle graphics. The code snippets include programs to check if a number is natural, even or odd, find the largest of three numbers, calculate average marks, draw shapes like circles, triangles, squares and stars. Input is taken from the user and output is printed based on various conditions checked in the programs.

Uploaded by

ammarahn0
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Python Doc (Input and Output)

The document contains 17 code snippets that demonstrate various Python programming concepts like data types, conditional statements, loops, functions and turtle graphics. The code snippets include programs to check if a number is natural, even or odd, find the largest of three numbers, calculate average marks, draw shapes like circles, triangles, squares and stars. Input is taken from the user and output is printed based on various conditions checked in the programs.

Uploaded by

ammarahn0
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

1) NATURAL NUMBER

INPUT

number=int(input("Enter a number: "))

if number > 0:

print("Entered number is a natural number")

else:

print("Entered number is not a natural number")

OUTPUT

Enter a number: 50

Entered number is a natural number

Enter a number: -50

Entered number is not a natural number

2) EVEN AND ODD NUMBERS

INPUT

num=int(input("Enter a number: "))

if (num%2) == 0:

print(num,"is even number")

else:

print(num,"is odd number")

OUTPUT

Enter a number: 15

15 is odd number

Enter a number: 30

30 is even number
3) INTEGER NUMBER

INPUT

# input three integer numbers

a=int(input("Enter A: "))

b=int(input("Enter B: "))

c=int(input("Enter C: "))

# conditions to find largest

if a>b:

if a>c:

g=a

else:

g=c

else:

if b>c:

g=b

else:

g=c

# print the largest number

print("Greater = ",g)

OUTPUT

Enter A: -50

Enter B: -100

Enter C: 0

Greater = 0
4) SUBJECT MARKS

INPUT

m1 = int(input("Enter first subject marks: "))

m2 = int(input("Enter second subject marks: "))

m3 = int(input("Enter third subject marks: "))

m4 = int(input("Enter fourth subject marks: "))

m5 = int(input("Enter fifth subject marks: "))

avg = (m1 + m2 + m3 + m4 + m5) / 5;

print ("Average Marks =", avg)

if avg > 100:

print("Average marks is more than 100")

else:

print("Average marks is less than 100")

OUTPUT

Enter first subject marks: 100

Enter second subject marks: 101

Enter third subject marks: 150

Enter fourth subject marks: 170

Enter fifth subject marks: 200

Average Marks = 144.2

Average marks is more than 100

Enter first subject marks: 90

Enter second subject marks: 95

Enter third subject marks: 92

Enter fourth subject marks: 93


Enter fifth subject marks: 99

Average Marks = 93.8

Average marks is less than 100

5) GREATER OR SMALLER NUMBER

INPUT

# input three integer numbers

a=int(input("Enter A: "))

b=int(input("Enter B: "))

c=int(input("Enter C: "))

if (a>b) and (a>c) :

print (a," is greater")

elif (b>a) and (b>c) :

print (b,"is greater")

else:

print(c,"is greater")

OUTPUT

Enter A: 50

Enter B: 45

Enter C: 40

50 is greater

Enter A: 100

Enter B: 300

Enter C: 250

300 is greater

Enter A: 5
Enter B: 50

Enter C: 500

500 is greater

6) STUDENT MARKS FAILED

INPUT

marks=int(input("Enter marks scored: ")

if marks < 50:

print ("The student has failed")

OUTPUT

Enter marks scored : 45

The student has failed

7) STUDENT MARKS PASSED/FAILED

INPUT

marks=int(input("Enter marks scored: ")

if marks < 50:

print ("The student has failed")

else:

print(“The student has failed”)

OUTPUT

Enter marks scored : 45

The student has failed

Enter marks scored : 55

The student has passed

8) YEAR AND LEAP YEAR

INPUT
year = int (input("Enter a year"))

if((( year%4--0) and (year%100!-0)) or (year %400--0)):

print(year,"is a leap year")

else:

print(year,"is not a leap year")

(OUTPUT)

Enter a year:2000

2000 is a leap year

Enter a year: 2001

2001 is not a leap year

9) QUANTITY

INPUT

qty=int(input("Enter the quantity: "))

if qty<=2:

print("Total cost=INR: ",qty*20)

elif qty >=3 and qty<=5:

print("Total cost=INR: ",qty*18)

elif qty >=6 and qty<= 10:

print("Total cost=INR: ",qty*15)

else:

print("Total cost=INR: ",qty*10)

OUTPUT

Enter the quantity: 8

Total cost=INR: 120

Enter the quantity: 4


Total cost=INR: 72

Enter the quantity: 1

Total cost=INR: 20

Enter the quantity: 11

Total cost=INR: 110

10) DRAW A spiral round

INPUT

# draw spiral circle in Python Turtle

import turtle

toto=turtle.Turtle()

toto.shape("turtle")

toto.screen.bgcolor("light blue")

toto.color("green")

r=10

for i in range(100):

toto.circle(r+i,60)

turtle.done()

OUTPUT

11)DRAW A PENTAGON

INPUT
# draw pentagon in Python Turtle

import turtle

toto=turtle.Turtle()

toto.shape("turtle")

toto.screen.bgcolor("light blue")

toto.color("green")

for i in range(5):

toto.forward(100)

toto.left(72)

turtle.done()

OUTPUT

12) DRAW A TRIANGLE

INPUT

# draw triangle in Pytho Turtle

import turtle

toto=turtle.Turtle()

toto.shape("turtle")

toto.screen.bgcolor("light blue")
toto.color("green")

for i in range(3):

toto.forward(100)

toto.left(120)

turtle.done()

OUTPUT

13) DRAW A SQUARE

INPUT

# draw square in Python Turtle

import turtle

screen= turtle.Screen() toto.right(90)

screen.bgcolor("light blue") toto.forward(45)

toto=turtle.Turtle() toto.right(90)

toto.right(90) toto.forward(45)

toto.forward(45) OUTPUT

toto.right(90)

toto.forward(45)

toto.right(90)

toto.forward(45)
output :

14) WHOLE NUMBER

INPUT

num=int(input("Enter a number: "))

if num >= 0:

print("The entered number is a whole number")

else:

print("The entered number is not a whole number")

OUTPUT

Enter a number: 5

The entered number is a whole number

Enter a number: -5

The entered number is not a whole number

15) GRADES

INPUT

per=int(input("Enter the percentage: "))

if per>=80 and per<=100:

print("Grade = A ")

elif per>=70 and per<=79:

print("Grade = B ")

elif per>=60 and per<=69:

print("Grade = C ")
elif per>= 50 and per<=59:

print("Grade = D ")

elif per>=40 and per<=49:

print("Grade = E ")

else:

print("Grade = F ")

OUTPUT

Enter the percentage: 91

Grade = A

Enter the percentage: 39

Grade = F

16) TO FIND IF THE CHARACTER ENTERED IS A LETTER OF THE ALPHABET/DIGIT/SPECIAL

CHARACTER

INPUT

ch=input("Enter a character: ")

if(((ch>= 'a') and (ch<='z')) or ((ch>= 'A') and (ch<='z'))):

print("Entered character is an alphabet")

elif ((ch>='0') and (ch>='9')):

print("Entered character is a digit")

else:

print("Entered character is a special character")

OUTPUT

Enter a character: a

Entered character is an alphabet

Enter a character: T
Entered character is an alphabet

Enter a character: 8

Entered character is a digit

Enter a character: $

Entered character is a special character

17) DRAWING A STAR

INPUT

import turtle

toto= turtle.Turtle()

toto.shape("turtle")

toto.screen.bgcolor("light blue")

toto.color('red')

toto.begin_fill()

toto.fillcolor("purple")

for i in range(5):

toto.forward(200)

toto.right(144)

toto.end_fill()

turtle.done()

OUTPUT
All the best

You might also like