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

1PythonBasicPrograms

Uploaded by

daksh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

1PythonBasicPrograms

Uploaded by

daksh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment 1

Python Programming Assignment 1 (Basic+ condition statements)

1. To display the message “My first program” and XI in separate lines on screen.

print (" My First Program")


print(“ XI ”)

Output:
My First Program
XI

P2 Input 2 numbers. Add them and display the result.

num1 = 1.5
#num1 is assigned the value 1.5
num2 = 6.3
print('The sum is ',num1+num2)

Output :

The sum is 7.8

P3 ) Assign values to Principle, rate, Time. Display Simple interest .

p=1000
r=5
t=2
si=(p*r*t)/100
print("Simple Interest is Rs ",si)

Output
Simple Interest is Rs 100

P4) Let the user Input values of Principle, rate, Time. Display Simple Interest

p=input("Enter the value for Principle amount : ")


r=input("Enter the value for rate : ")
t=input("Enter the value for Time : ")

# int changes string data type to integer


p=int(p)
r=int(r)
t=int(t)
si=int((p*r*t)/100)
print("Simple Interest is Rs ",si)

Output:
Enter the value for Principal : 100
Enter the value for rate : 2
Enter the value for Time : 3
Simple Interest is Rs 6

P5) Assign strings ‘hello’ and “world” to two string variables. Display their values.

a = 'hello'
# single and double quotes both can be used to #
enclose strings. a is
print(a)
b = "world"
print(b)

Output:

hello
world

P6. Input a character. Display its ASCII value

# Program to find the ASCII value of the given character

c = input("Enter a character: ")

print("The ASCII value of '" + c + "' is",ord(c))

Output:
Enter a character: A
The ASCII value of 'A' is 65

Enter a character: a
The ASCII value of 'a' is 97
P7: Let the user Input radius of a circle . Display its Area . (A= pi* r*r)

pi= 3.14
r = int(input(“Pl enter the Radius of circle”))

a= pi* r *r
print (“Area is”, a)
P

Output:

Enter the radius of the circle : 2


The area of the circle with radius 2.0 is: 12.56

P8:
Input Temperature in Degrees Fahrenheit. Display in Celcius.

ftemp = float(input("Enter Temperature in Fahrenheit "))


ctemp = (ftemp-32)*5/9;
print ("\n Temp in Celcius is ",ctemp)

Output:
Enter Temperature in Fahrenheit 132

Temp in Celcius is 55.55555555555556

P9:

(Concatenation)
Let the user input his/her first name and Last name. Display Hello, lastname then First name.

fname = input("Input your First Name : ")


lname = input("Input your Last Name : ")
print ("Hello " + lname + " " + fname)
# in Strings + is for concatenation- means displaying side by side.

Output
Input your First Name : Agamjot
Input your Last Name :Singh
Hello Singh Agamjot
P10:

To input 2 numbers and swap them using third variable

a= input("Enter first number ")


a= float(a)
b=input("Enter second number ")
b= float(b)
temp = a
a=b
b=temp
print ("The first number now is ",a)
print ("The second number now is ", b)

Output:
Enter first number 23
Enter second number 45

The first number now is 45.0

The second number now is 23.0

P11:
To input 2 numbers and swap them WITHOUT using third variable

a= input("Enter first number ")


a= float(a)
b=input("Enter second number ")
b= float(b)
a = a + b;
b = a - b;
a = a - b;
print("After swap:")

print ("The first number now is ",a)


print ("The second number now is ",b)

Output:
Enter first number 23
Enter second number 45

After swap:

The first number now is 45.0

The second number now is 23.0


P12: Enter time in seconds. Display in hours, minutes, seconds

s= int(input("Enter Time in seconds"))


m = s/60;
s = s%60;
h = m/60;
m = m%60;
print("Hrs "+str(h)+" Minutes = "+str(m)+" seconds = "+str(s));

Output
Enter Time in seconds 150000
Hrs 41.666666666666664 Minutes = 40.0 seconds = 0

You might also like