Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Computer Program Homework

Uploaded by

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

Computer Program Homework

Uploaded by

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

1.

a = eval(input("Enter 1st Number"))


b = eval(input("Enter 2nd Number"))
c = eval(input("Enter 3rd Number"))

if(a > b and a > c):


print("" ,a, "is the Greatest Number")
elif(b > a and b > c):
print("" ,b, "is the Greatest Number")
else:
print("" ,c, "is the Greatest Number")

2.

a = int(input("Enter Year"))

if(a%400 ==0):
print("It is a leap year")
else:
if(a%4 ==0 and a%100 !=0):
print("It is a leap year")
else:
print("It is not a leap year")

3.
b=1
while(b==1):
print(" 1. <-- Celsius to Fahrenheit")
print(" 2. <-- Fahrenheit to Celsius")
print(" 3. <-- Exit")
a = int(input("Enter 1,2 or 3 \n "))
if(a == 1):
y = eval(input("Enter Celsius :-"))
c = (y*1.8) + 32
print("",y,"Celsius is",c,"Fahrenheit \n")
elif(a == 2):
z = eval(input("Enter Fahrenheit :-"))
f = (z - 32) * 5/9
print("" ,z, "Fahrenheit is" ,f,"Celsius \n")
elif(a == 3):
exit()
else:
print("Invalid Code Number")

4.

a=eval(input("Enter Length Of 1st Side"))


b=eval(input("Enter Length Of 2nd Side"))
c=eval(input("Enter Length Of 3rd Side"))
if( a == b and a == c and b == c):
print(" Its An Equilateral Triangle")
elif( a == b or a == c or b == c):
print(" Its An Isoceles Triangle")
else:
print(" Its A Scalene Triangle")

5.

a = input(" Enter Alphabet ")


b = a.lower()
if( b == "a" or b == "e" or b == "i" or b == "o" or b == "u"):
print("Its A Vowel")
else:
print("Its A Consonant")

6.

a = input("Enter Month")
b = a.lower()

if(b == 'january' or b == 'march' or b == 'may' or b == 'july' or b == 'august' or


b == 'october' or b == 'december'):
print("It has 31 Days")
elif(b == 'april' or b == 'june' or b == 'september' or b == 'november'):N
print("It has 30 days")
elif(b == 'february'):
y=int(input("Enter Year"))
if(y%400 ==0):
print("It has 29 Days")
else:
if(a%4 ==0 and a%100 !=0):
print("It has 29 Days")
else:
print("It has 28 Days")

7.

a = 65

while(a< 123):
print(chr(a))
a = a + 1

8.
a = -1

while(a<122):
x = chr( 1 + a)
print("The ASCII Value Of -" ,x , "- is:" , a+1)
a = a + 1

OR

a = -1

while(a>-2):
x = chr( 1 + a)
print("The ASCII Value Of -" ,x , "- is :" , a+1)
a = a + 1

9.

a=eval(input("Enter Number: -"))


b = 1

while(b < 11):


print("",a," x ",b,"=",a*b ,"\n")
b = b + 1

OR

a=eval(input("Enter Number: -"))


b = 1

while(b > 0):


print("",a," x ",b,"=",a*b ,"\n")
b = b + 1

10.

a=int(input("Enter Number: -"))

while(a > 0):


print("",a,"\n")
a = a - 1

11.

a=int(input("Enter Number :-"))


s = 0
b = 10
while(a > 0):
c = a%b
s = s+c
a = a//10
print(s)

12.

n = int(input("Enter Number :-"))


s = 0
if(n%2 == 0):
a = n
else:
a = (n - 1)

while(a > 0):


s = s+a
a = a-2
print(s)

13.

n = int(input("Enter Number :-"))


s = 0
if(n%2 == 1):
a = n
else:
a = (n - 1)

while(a > 0):


s = s+a
a = a-2
print(s)

14

a = int(input("Enter Number :-"))


x = a
y = a
n = 0
while(x > 0):
x = x//10
n = n + 1
if(n == 1):
print(a)
else:
aa = y%10
bb = y // (10**(n-1))
s = (y - (bb * (10**(n-1)))) - aa
ss = (s + (aa * (10**(n-1)))) + bb
print(ss)
15.

a = int(input("Enter Number :-"))


x = a
y = a
n = 0
while(x > 0):
x = x//10
n = n + 1

if(n == 1):
print(a)
else:
aa = y%10
bb = y // (10**(n-1))
sm = aa + bb
print(sm)

16.

a = int(input("Enter Number :-"))


x = a
y = a
n = 0
while(x > 0):
x = x//10
n = n + 1

if(n == 1):
print("First and last digit is ",a)
else:
aa = y%10
bb = y // (10**(n-1))
print("First Digit is ",bb," and last digit is",aa)

17.

a=int(input("Enter Number :-"))


s = 1
b = 10
while(a > 0):
c = a%b
s = s * c
a = a//10
print(s)

18.

a=int(input("Enter Number :-"))


z = 0
while(a > 0):
b = a%10
z = (z*10) + b
a = a//10

print(z)

19.

b = 1
while(b == 1):
w = eval(input("Enter Work Done = "))
t = eval(input("Enter Time = "))
p = w / t
print("Power = ",p," Watt")

20.

a = int(input("Enter Number :-"))


p = 1
while(a > 0):
p = p * a
a = a - 1
print(p)

21.

a = int(input("Enter Number :-"))


x = a
n = 0
while(x > 0):
x = x//10
n = n + 1
print("The Number Of Digits =",n)

z = a
s = 0
while(z > 0):
b = z%10
s = s + (b**n)
z = z//10

if(a == s):
print("Its an Armstrong Number")
else:
print("It is not an Armstrong Number")
#Eg - 153 , 9474 , 24678050

22.

#Eg - 153 , 9474 , 24678050


n=int(input("Enter Number :-"))
while(n > 0):
x = n
m = 0
while(x > 0):
x = x//10
m = m + 1

z = n
s = 0
while(z > 0):
b = z%10
s = s + (b**m)
z = z//10

if(n == s):
print(n)
n = n-1
else:
n = n-1

23.

n=int(input("Enter Number :-"))


c = 0
a = n
if(n == 1):
print("It is neither prime nor composite")
else:
while(a > 0):
if(n%a == 0):
c = c + 1
a = a - 1
else:
a = a-1
if(c == 2):
print("It is a prime number")
else:
print("It is a composite number")

24.

a=int(input("Enter Number :-"))


y = a
z = 0
while(a > 0):
b = a%10
z = (z*10) + b
a = a//10

if(y == z):
print("It is a Palindrome Number")
else:
print("It is not a Palindrome Number")

You might also like