0% found this document useful (0 votes)
10 views14 pages

Python Programs for Beginners

The document contains a series of Python programs, each with a specific aim, source code, and output. Programs include tasks such as printing a formatted string, performing arithmetic operations, calculating averages, swapping numbers, checking voting eligibility, finding the largest number, determining odd/even status, and creating various types of charts. Each program's source code is provided along with the expected output and confirmation of successful execution.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views14 pages

Python Programs for Beginners

The document contains a series of Python programs, each with a specific aim, source code, and output. Programs include tasks such as printing a formatted string, performing arithmetic operations, calculating averages, swapping numbers, checking voting eligibility, finding the largest number, determining odd/even status, and creating various types of charts. Each program's source code is provided along with the expected output and confirmation of successful execution.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON PROGRAMS

PROGRAM NO-1

AIM - Write a Python program to print the following string in a specific format.

Twinkle, twinkle, little star,


How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are!

SOURCE CODE

print("Twinkle, twinkle, little star, \n\tHow I wonder what you are! \n\t\tUp above the
world so high, \n\t\tLike a diamond in the sky. \nTwinkle, twinkle, little star, \n\tHow I
wonder what you are!")

OUTPUT

Twinkle, twinkle, little star,


How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are!

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO – 2

AIM - Write a Python program to obtain two numbers and check all the arithmetic
operations. [Addition, subtraction, Multiplication and Division]

SOURCE CODE

num1=int(input("Enter first number :"))


num2=int(input("Enter second number :"))
sum=num1+num2
diff=num1-num2
prod=num1*num2
div=num1/num2
print("The two numbers are : ",num1,"&",num2)
print("Sum is : ",sum)
print("Difference is : ",diff)
print("Product is : ",prod)
print("Quotient is : ",div)

OUTPUT

Enter first number :20


Enter second number :5
The two numbers are : 20 & 5
Sum is : 25
Difference is : 15
Product is : 100
Quotient is : 4.0

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO – 3

AIM - Write a Python program to input three numbers and print their average.

SOURCE CODE

x=int(input("Enter first number :"))


y=int(input("Enter second number :"))
z=int(input("Enter third number :"))
print("The three numbers are : ",x,y,z)
avg=(x+y+z)/3
print("Average of given numbers :",avg)

OUTPUT

Enter first number :14


Enter second number :12
Enter third number :13
The three numbers are : 14 12 13
Average of given numbers : 13.0

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO – 4

AIM - Write a Python program to input three numbers and swap them as this : 1st
number becomes the 2nd number, 2nd number becomes the 3rd number and the 3rd
number becomes the 1st number.

SOURCE CODE

x=int(input("Enter first number :"))


y=int(input("Enter second number :"))
z=int(input("Enter third number :"))
print("The original numbers are : ",x,y,z)
x,y,z = y,z,x
print("After swapping :",x,y,z)

OUTPUT

Enter first number :8


Enter second number :22
Enter third number :54
The original numbers are : 8 22 54
After swapping : 22 54 8

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO-5

AIM - Write a Python program to input age from user and print if as per the input-age,
one is eligible to vote or not.

SOURCE CODE

age=int(input("Enter age :"))

if age>=18:

print("18 and more, you are eligible to vote")

else:

print("Under 18 , you are not eligible to vote")

OUTPUT

Enter age :25


18 and more, you are eligible to vote

Enter age :16


Under 18 , you are not eligible to vote

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO-6

AIM- Write a Python program to accept three integers and print the largest of three
numbers make use of only if

SOURCE CODE

x=y=z=0

x= float (input("Enter first number : ") )

y= float (input("Enter second number : ") )

z= float (input("Enter third number : ") )

max=x

if y > max :

max = y

if z > max :

max = z

print("Largest nimber is" , max )

OUTPUT

Enter first number: 7.235

Enter second number: 6.99

Enter third number: 7.533

Largest number is 7.533

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO-7

AIM- Write a Python program that takes a number and check whether the given number
is odd or even

SOURCE CODE

num = int (input("Enter an integer : "))

if num % 2== 0 :

print(num, " is EVEN number.")

else :

print(num, " is ODD number.")

OUTPUT

Enter an integer : 8

8 is EVEN number .

Enter an integer : 23

23 is ODD number.

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO-8

AIM- Write a program to print all items from a list containing some colour name in it

SOURCE CODE

colist=[ " Blue "," Green " , " Yellow " , " Orange "," Red " , " Brown "]

for colname in colist:

print (colname)

OUTPUT

Blue
Green
Yellow
Orange
Red
Brown

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO-9

AIM- Write a program to compute total marks of different subjects stored in the form of
a list

SOURCE CODE

marks= [93, 78, 69, 71, 65]

print ("Marks are :" ,marks)

total=0

for sm in marks:

total= total + sm

print ( " The total marks are : ",total)

OUTPUT

Marks are : 93, 78, 69, 71, 65

The total marks are: 376

RESULT- The source code is executed successfully and the output was verified.
PROGRAM NO-10

AIM- Write a program to print table of a number ,say 5

SOURCE CODE

num = 5

for a in range (1,11):

print(num, 'x ' , a, '=' , num * a)

OUTPUT

5x 1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

RESULT- The source code is executed successfully and the output was verified.
Program No-11

Aim: Write a python program to create a line chart

Source Code

import [Link] as plt


week= [1,2,3,4]
prices= [40,80,100,50]
[Link](week,prices)
[Link]=("Weeks")
[Link]=("Prices")
[Link]()

Output

Result The source code is executed successfully and the output was verified
Program No-12

Aim: Write a python program to create a bar graph

Source Code

import [Link] as plt


Info=['Gold','Silver','Bronze','Total']
Australia =[80,59,59,198]
[Link](Info,Australia)
[Link]("Medal types ")
[Link]=("Australia Medal count ")
[Link]()

Output

Result The source code is executed successfully and the output was verified
Program No-13
Aim: Write a python program to create a pie chart

Source Code

import [Link] as plt


Col=[80000,12000,9800,11200,15500,7300]
Section=['A',' B',' C','D','E', 'F']
[Link]("Volunteering Week collection ")
[Link](Col,labels=Section)
[Link]()
Result The source code is executed successfully and the output was verified

Result The source code is executed successfully and the output was verified

You might also like