Python Programs

Write a program that asks the user to enter one’s name and age. Print out a message addressed to the user that tells the user the year in which he/she will turn 100 years old.

from datetime import datedates = date.today()name = input(“Enter your Name”)age = int(input(“Enter your Age”))diff = 100 – ageresult_year = dates.year + diffprint(“You will turn 100 years old in “, result_year)

Write a program that asks the user to enter one’s name and age. Print out a message addressed to the user that tells the user the year in which he/she will turn 100 years old. Read More »

Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate = R% per annum and Time = T years.

P = int(input(“Enter Principal Amount or Money lent”))R= int(input(“Enter Rate of Interest”))T = int(input(“Enter Time Period”))SI = (P*R*T)/100amt = P + SIprint(“Amount Payable is = ” , amt)

Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate = R% per annum and Time = T years. Read More »

Python assignment statements Examples

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 variable stationary.d) Assign the strings ‘Mohandas’, ‘Karamchand ’, and ‘Gandhi’ to variable first, middle and last.e) Assign the concatenated

Python assignment statements Examples Read More »

Which of the following identifier names are invalid and why?

Ans: a) Serial_no. Invalid We cannot use any punctuation mark in identifier name b) 1st_Room Invalid Variable name cannot begin with number c) Hundred$ Valid We can use ‘$‘anywhere in variable name except at the beginning. d) Total Marks Invalid We cannot provide space between the names of variable. e) Total_Marks Valid We can use

Which of the following identifier names are invalid and why? Read More »

Explain the difference between import and from import statement, with example.

import <module> It import entire module and so everything inside the module will be imported like functions, constant, variables.In this way after importing the module we can use any function of imported module as per given syntax-module.<functionname>() For example import mathprint(math.pi)print(math.sum([10,20])) from <module> import statement from <module> import statement imports selected items , but to

Explain the difference between import and from import statement, with example. Read More »

What do you understand by standard library of Python?

Standard library is built in library with predefined modules in python. It is automatically installed with python installation and we can access any object of these module without referring their module name and dot notation. Some common module of python standard library are- Math N NumPy SciPy tkniter Matplotlib

What do you understand by standard library of Python? Read More »

Why should the form import statement be avoided to import objects?

We should avoid importing any object like from <module> import <object> because in this way object is added in current namespace and if any existing variable’s name resembles with the variable imported via module, so imported variable is ignored.

Why should the form import statement be avoided to import objects? Read More »

error: Content is protected !!