0% found this document useful (0 votes)
30 views12 pages

Document 2

The document provides code snippets for 10 Python programs that take user input and perform calculations or logical checks. The programs include calculating square and cube, printing number tables, finding largest of 3 numbers, calculator based on operator, checking voting eligibility, finding factorial, Celsius to Fahrenheit conversion, finding ASCII value, summing numbers in a range, and printing even numbers in a range.

Uploaded by

kamaalp6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views12 pages

Document 2

The document provides code snippets for 10 Python programs that take user input and perform calculations or logical checks. The programs include calculating square and cube, printing number tables, finding largest of 3 numbers, calculator based on operator, checking voting eligibility, finding factorial, Celsius to Fahrenheit conversion, finding ASCII value, summing numbers in a range, and printing even numbers in a range.

Uploaded by

kamaalp6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM 1-

Q-Write a python to take input for a number calculate and find its
square and cube?
Ans-a=int(input("Enter Number:"))
square=a**2
print("The square of",a,"is:",square)
cube=a**3
print("The cube of",a,"is:",cube)
OUTPUT OF PROGRAM 1-
PROGRAM 2-
Q-Write a python script to take input for a number and print its
table?
Ans- b=int(input("Enter Number:"))
t=1
for a in range(1,11):
t=b*a
print(b,"*",a,"=",t)
OUTPUT OF PROGRAM 2-
PROGRAM 3-
Q-Write a python script to take input for 3 numbers, check and
print the largest
number?
Ans- a=int(input("Enter 1st number :"))
b=int(input("Enter 2nd number :"))
c=int(input("Enter 3rd number :"))
if a>b:
if a>c:
print(a,"is the largest"."."."&",c)
else:
print(c,"is the largest"."."."&"c)
else:
if b>c:
print(b,"is the largest"a","b"&",c)
else:
print(c,"is the largest"a","b"&",c)
if a==b==c:
print("ALL THE NUMBER ARE EQUAL")
OUTPUT OF PROGRAM 3-
PROGRAM 4-
Q-Write a python script to take input for 2 numbers and an
operator (+, -,*, /). Based on the operator calculate and print the
result?
Ans- num1 = int(input("Enter First Number: "))
num2= int(input("Enter Second Number: "))
ch= input("Enter any of these char for specific operation/:")
result = 0
if ch == '+':
result = num1 + num2
elif ch == '-':
result = num1 - num2
elif ch == '*':
result = num1 * num2
elif ch == '/':
result = num1 / num2
else:
print("Input character is not recognized!"
print(num1, ch, num2, ":", result)
OUTPUT OF PROGRAM 4-

.
PROGRAM 5-
Q-Write a python script to take input for name and age of a person
check and print whether the person can vote or not?
Ans-name=str(input("Enter Name:"))
age=int(input("Enter Age:"))
if age>=18:
print("\n\nHi",name, "You Can Vote.")
else:
d=18-age
print("\n\nHi",name, "You Can't Vote Now
But You Can Vote After",d,"Years.")
OUTPUT OF PROGRAM 5-
PROGRAM 6-
Q-Write a python script to take input for a number and print its
factorial?
Ans-v=int(input("Enter start value:"))
fact=1
for d in range(v,1,-1):
fact*=d
print(fact)
OUTPUT OF PROGRAM 6-
PROGRAM 7-
Q-Program to Convert Celsius To Fahrenheit.
(F=32+c*9/5)
Ans-c=float(input("Enter Temperature in Celsius:"))
f=32+c*9/5
print("Temperature in Fahrenheit:",f)
OUTPUT OF PROGRAM 7-
PROGRAM 8-
Q-Write Python Program to Find ASCII Value of given Character?
Ans- a= input("Enter value:")
b=ord(a)
print("The ASCII value of",end="")
print(a,end)
print("'is:",b)
OUTPUT OF PROGRAM 8-
PROGRAM 9-
Q-Python program to print the sum of all numbers in the given
range?
Ans-v=int(input("Enter first value:"))
h=int(input("Enter second value:"))
sum = 0
for i in range(v,h+1):
sum+=i
print("The sum of number between",v,"and",h,"is:", sum)
OUTPUT OF PROGRAM 9-
PROGRAM 10-
Q-Python program to print all even numbers
in given range?
Ans-f=int(input("Enter the start value:"))
k=int(input("Enter the end vlaue:"))
for p in range(f,k+1):
if p%2==0:
print(p)
OUTPUT OF PROGRAM 10-

You might also like