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

Python Programming Study Materials

The document discusses basics of Python programming including: 1. Printing a string in a specific formatted output 2. Displaying the current date and time 3. Calculating the area of a circle based on user input radius It provides code examples for printing formatted text, displaying date and time, calculating circle area, reversing first and last name, generating lists and tuples from comma separated user input, summing and multiplying list items, and finding the largest number in a list.

Uploaded by

majhis145
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)
26 views

Python Programming Study Materials

The document discusses basics of Python programming including: 1. Printing a string in a specific formatted output 2. Displaying the current date and time 3. Calculating the area of a circle based on user input radius It provides code examples for printing formatted text, displaying date and time, calculating circle area, reversing first and last name, generating lists and tuples from comma separated user input, summing and multiplying list items, and finding the largest number in a list.

Uploaded by

majhis145
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/ 3

Python Programming

Basics of Python:

1. Write a Python program to print the following string in a specific format (see the output).
Sample String : "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"
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

Answer:

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!")

2. Write a Python program to display the current date and time.

Answer:

import datetime
print(datetime.datetime.now())

3. Write a Python program that calculates the area of a circle based on the radius entered by
the user.
Sample Output :
r = 1.1
Area = 3.8013271108436504
Answer:
from math import pi
r = float(input ("Input the radius of the circle : "))
print ("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2))

5. Write a Python program that accepts the user's first and


last name and prints them in reverse order with a space
between them.

Answer:
fname = input("Input your First Name : ")
lname = input("Input your Last Name : ")

Computer Age | Sandip Majhi


print ("Hello " + lname + " " + fname)

6. Write a Python program that accepts a sequence of comma-


separated numbers from the user and generate a list and a
tuple of those numbers.
Sample data : 3, 5, 7, 23
Output :
List : ['3', ' 5', ' 7', ' 23']
Tuple : ('3', ' 5', ' 7', ' 23')

Answer:
values = input("Input some comma seprated numbers : ")
list = values.split(",")
tuple = tuple(list)
print('List : ',list)
print('Tuple : ',tuple)

7. Write a Python program to sum all the items in a list.

Answer:

def sum_list(items):
sum_numbers = 0
for x in items:
sum_numbers += x
return sum_numbers

print(sum_list([1,2,-8]))

8. Write a Python program to multiply all the items in a list.

Answer:
def multiply_list(items):
tot = 1
for x in items:
tot *= x
return tot
print(multiply_list([1,2,-8]))

9. Write a Python program to get the largest number from a


list.

Answer:

def max_num_in_list( list ):


max = list[ 0 ]

Computer Age | Sandip Majhi


for a in list:
if a > max:
max = a
return max
print(max_num_in_list([1, 2, -8, 0]))

Computer Age | Sandip Majhi

You might also like