Worksheet 1: Python Fundamentals

Python Fundamental Worksheet:1


1.      Which of the following identifier names are invalid and why? 
Serial_no.
1st_Room
Total_Marks  
total-Marks
 Hundred$
_Percentage
Total  Marks
 True

2  Write the corresponding Python assignment statements:

a) Assign 10 to variable length and 20 to variable breadth.

b) Assign the average of values of variables length and breadth to a variable sum.

c) Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.

d) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.

e) Assign the concatenated value of string variables first, middle and last to variable fullname. Make sure to incorporate blank spaces appropriately between different parts of names.

3. Add a pair of parentheses to each expression so that it evaluates to True.

a) 0 == 1 == 2

b) 2 + 3 == 4 + 5 == 7

c) 1 < -1 == 3 > 4

4.  Which data type will be used to represent the following data values and why?

a) Number of months in a year

b) Resident of Delhi or not

c) Mobile number

d) Pocket money

e) Volume of a sphere

f) Perimeter of a square

g) Name of the student

h) Address of the student

5. Give the output of the following when num1 = 4, num2 = 3, num3 = 2

a)         num1 += num2 + num3

            print (num1)

b)         num1 = num1 ** (num2 + num3)

            print (num1)

c)         num1 **= num2 + num3

d)         num1 = '5' + '5'

            print(num1)

e)         print(5 % 10 + 10 < 50 and 29 <= 29)

f)         print((0 < 6) or (not(10 == 6) and (10<0)))

6. What is the output of 0.1 +0.2 ==0.3?

(i) True                 (ii) False               (iii) Error              (iv) machine dependent

Python Programming : 

  • Write a Python program to convert temperature in degree Celsius to degree Fahrenheit. If water boils at 100 degree C and freezes as 0 degree C, use the program to find out what is the boiling point and freezing point of water on the Fahrenheit scale.     (Hint: T(°F) = T(°C) × 9/5 + 32)
  • Write a Python program to calculate the amount payable if money has been lent on simple interest.
Principal or money lent = P, Rate of interest = R% per annum and Time = T years.
Then Simple Interest (SI) = (P x R x T)/ 100.
Amount payable = Principal + SI.
P, R and T are given as input to the program.

  • Write a program to calculate in how many days a work will be completed by three persons A, B and C together. A, B, C  take x days, y days and z days respectively to do the job alone. The formula to calculate the number of days if they work  together is xyz/(xy + yz + xz) days where x, y, and z are given as input to the program.

  • Write a program to enter two integers and perform all arithmetic operations on them.
  • Write a program to swap two numbers using a third variable.
  • Write a program to swap two numbers without using a third variable.
  • Write a program to repeat the string ‘‘GOOD MORNING” n times. Here ‘n’ is an integer entered by the user.
  •  Write a program to find average of three numbers. 
  • The volume of a sphere with radius r is 4/3πr3. 
  • Write a Python program to find the volume of spheres with radius 7cm, 12cm, 16cm, respectively.
  • Write a program that asks the user to enter their name and age. Print a message addressed to the user that tells the user the year in which they will turn 100 years old.
  •  The formula E = mc2 states that the equivalent energy (E) can be calculated as the mass (m) multiplied by the speed of light (c = about 3×108 m/s) squared.