122 PythonBasicSheet
122 PythonBasicSheet
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 :
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:
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
Output:
Program 7
Write a Python program that returns a string that is n (non-negative integer) copies of a
given string.
Solution:
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
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):
check('f')
check('i')
Output: