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

122 PythonBasicSheet

Uploaded by

Subhodeep Chanda
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)
8 views

122 PythonBasicSheet

Uploaded by

Subhodeep Chanda
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
You are on page 1/ 9

BASIC PYTHON PROBLEM SHEET

ASSIGNMENT

Subhodeep Chanda
Department of Physics
Roll No: 122
Paper Code – C1PH230112P
UG (NEP) Semester 1 (July – December 2024)
Program 1:
Print a table of 13.1 from 1 to 12

Solution:

Program 2:
Write a Python program to print the following string using the 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
Solution:

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

Program 3
Write a Python program that calculates the area of a circle based on the radius entered by
the user. Hints : Define a function first. Import anything you need from the math module.

Solution:

r = float(input("enter radius of circle="))


enter radius of circle=34.562
>>> area = f'{3.14*r*r: 0.01f}'
>>> print("area of circle is=", area)
Program 4
Write a Python program to display the first and last colors from the following list.
color_list = ["Red","Green","White" ,"Black"]

Solution:
color_list = ["Red","Green","White","Black"]
print(color_list[0])
print(color_list[3])

Output:

Program 5
Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn.
Show output for n=5 and n=15.

Solution:

def compute_expression(n):
nstr = str(n)
nn = int(nstr * 2)
nnn = int(nstr * 3)

result = n + nn + nnn
return result
print("For n=5:", compute_expression(5))
print("For n=15:", compute_expression(15))
Output:

Program 6
Write a Python program to calculate the difference between a given number and 17. If the
number is greater than 17, return twice the absolute difference.

def difference_from_17(n):
if n > 17:
return 2 * (n - 17)
else:
return 17 - n

print("Result for 10:", difference_from_17(10))


print("Result for 20:", difference_from_17(20))

Output:
Program 7
Write a Python program that returns a string that is n (non-negative integer) copies of a
given string.

Solution:

def copies(text, n):


if n < 0:
return "n must be a non-negative integer"
return text * n

print("3 copies of 'hello':", copies("hello", 3))


print("0 copies of 'hello':",copies("hello", 0))

Output:

Program 8
Write a Python program that determines whether a given number (accepted from the user)
is even or odd, and prints an appropriate message to the user.

Solution:

def determine(n):
if n%2==0:
print("even")
else:
print("odd")

determine(17)
determine(2)
def determine(n):
quotient, remainder = divmod(n, 2)

if remainder == 0:
print( “even.")
else:
print(“odd.")

determine (17)
determine(6)

Output:
Program 9
Write a Python program that checks whether a specified value is contained within a group of
values. Test Data : 3 -> [1, 5, 8, 3] : True -1 -> [1, 5, 8, 3] : False

def present(value, group):


return value in group

print(present(3, [1, 5, 8, 3]))


print(present (-1, [1, 5, 8, 3]))

Output:

Program 10
Write a Python program to test whether a passed letter is a vowel or not

Solution:

vowels = ['a','e','i','o','u']
def check(letter):

return letter in vowels

check('f')
check('i')

Output:

You might also like