Coding
Coding
https://colab.research.google.com/drive/1ZK3MHz_tUUIx2oRu4QbrdOOjn4o7whdQ
"""
#-----------------------------------------------------------------------------------------------------------
#Program No:1
#input:
print("hello",name)
#hello Divyashree
#-----------------------------------------------------------------------------------------------------------
#Program No:2
#input:
#output:
#Name: Divyashree
#-----------------------------------------------------------------------------------------------------------
#Program No:3
#3. Write a Python program to input a number and check whether the entered number is even or
not
#input:
if n%2 == 0:
else:
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:4
#input:
if n%5 == 0:
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:5
#5. Write a Python program to read a month number and print corresponding month name
#input:
if n == 1:
print("january")
elif n == 2:
print("february")
elif n == 3:
print("march")
elif n == 4:
print("april")
elif n == 5:
print("may")
elif n == 6:
print("june")
elif n == 7:
print("july")
elif n == 8:
print("august")
elif n == 9:
print("september")
elif n == 10:
print("october")
elif n == 11:
print("november")
elif n == 12:
print("december")
#output:
#april
#-----------------------------------------------------------------------------------------------------------
#Program No:6
#6. Write a Python program to find the Square Root of a given number.
#input:
n=int(input("enter number:"))
print(n**0.5)
#output:
#enter number:36
#6.0
#-----------------------------------------------------------------------------------------------------------
#Program No:7
#7. Write a Python program to input angles of a triangle and check whether triangle is valid or not
#input:
a=int(input("enter angle1:"))
b=int(input("enter angle2:"))
c=int(input("enter angle3:"))
if a+b+c == 180:
print("triangle is valid")
else:
#output:
#enter angle1:60
#enter angle2:60
#enter angle3:60
#triangle is valid
#-----------------------------------------------------------------------------------------------------------
#Program No:8
#input:
area=base*height/2
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:9
#9. Write a Python program to check whether a person is eligible to vote or not.
#input:
age=int(input("enter your age:"))
else:
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:10
#input:
import random
print( random.random())
#output:
#0.9662836770371147
#-----------------------------------------------------------------------------------------------------------
#Program No:11
#input:
F=9/5*cel + 32
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:12
#input:
if op == '+':
elif op == '-':
elif op == '*':
elif op == '/':
else:
#output:
#Enter n1: 5
#Enter n2: 5
#-----------------------------------------------------------------------------------------------------------
#Program No:13
#13. Write a Python program to print the sum of first 10 numbers.
#input:
i=1
sum=0
i=i+1
sum=sum+i
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:14
#14. Write a Python program to input 3 numbers from user and print the maximum among them.
(with conditional operator)
#input:
n1=int(input("enter number:"))
n2=int(input("enter number:"))
n3=int(input("enter number:"))
else:
#output:
#enter number:6
#enter number:9
#enter number:3
#9
#-----------------------------------------------------------------------------------------------------------
#Program No:15
#15. Write a program to find the sum of odd numbers and even numbers from 1 to N, N entered
from user
#input:
N=int(input("enter number:"))
i=1
sum=0
while i <= N:
i=i+2
sum=sum+i
print("sum",sum,end=" ")
#output:
#enter number:11
#Program No:15
#15. Write a program to find the sum of odd numbers and even numbers from 1 to N, N entered
#input:
N=int(input("enter number:"))
i=0
sum=0
while i <= N:
i=i+2
sum=sum+i
print("sum",sum,end=" ")
#output:
#enter number:11
#-----------------------------------------------------------------------------------------------------------
#Program No:16
#16. Create a converter that will convert a distance in meters to feet and inches.
#input:
feet = distance*3.281
#output:
#Program No:16
#16. Create a converter that will convert a distance in meters to feet and inches.
#input:
inches= distance*0.0254
#output:
#Program No:17
#17. Write a Python program to read a character from the user and check whether it is a vowel or
consonant
#input:
else:
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:18
#input:
if str.isupper():
print("character is in uppercase")
else:
print("character is in lowercase")
#output:
#character is in lowercase
#-----------------------------------------------------------------------------------------------------------
#Program No:19
#19. Write a program to accept two numbers and one mathematical operator. Calculate and display
appropriate answer as shown below:
#input:
if op == '+':
print(n1,op,n2,"=",n1+n2)
#7
#-----------------------------------------------------------------------------------------------------------
#Program No:20
#20. Write a program to enter a number from the user and display the sum of all the digits in the
number.
#input:
sum = 0
for i in num:
sum += int(i)
#Program No:21
#21. Accept a year from the user and check whether it is leap year or not.
#input:
year=int(input("enter year:"))
else:
#output:
#enter year:2012
#------------------------------------------------------------------------------------------------------------
#Program No:22
#if the int is 12345, the output shall be "5 4 3 2 1", with a space separating the digits.
#input:
n=0
while num>0:
a = num%10
num = num - a
num = num/10
print(int(a),end="")
n=n+1
print(n)
#output:
#enter a number with multiple digit: 12345
#543215
#-----------------------------------------------------------------------------------------------------------
#Program No:23
#23. Accept a number N from the user and print the first N elements of the Fibonacci series.
#input:
x=0
y=1
z=0
while z<=n:
print(z,end=" ")
x=y
y=z
z=x+y
#0 1 1 2 3 5 8 13
#-----------------------------------------------------------------------------------------------------------
#Program No:24
#24. Calculate the area of triangle given its three sides. The formula or algorithm used is:
#input:
#output:
#-----------------------------------------------------------------------------------------------------------
#Program No:25
#25. Write a program that take input of 3 subjects marks out of 150. Count the percentage. P
#input:
print("DISTINCTION")
print("FIRST CLASS")
print("SECOND CLASS")
print("PASS CLASS")
print("fail")
#output:
#fail
#-----------------------------------------------------------------------------------------------------------
#Program No:26
#26. Accept the marks (out of 70) for 3 subjects (Maths, physics, chemistry) from the user and
#check if the student is eligible for admission based on the following criteria:
#input:
#i) Mathematics >= 50%, Physics >= 45%, Chemistry >= 60% Overall Percentage >= 65%
else:
#output:
#-----------------------------------------------------------------------------------------------------------
#Roll number:AU2040261 Name:Divyashree jadeja
#Program No:27
#27. Considering three numbers provided by the user as length of sides of a triangle,
# first check, if the values are valid for representing the sides of a triangle (i.e. whethera triangle can
be drawn using the given values)
#If the lengths of sides are valid, print the type of the triangle.
#input:
if a + b > c:
print("triangle is valid")
else:
if a == b == c:
print("Equilateral")
elif a == b or b == c or a == c:
print("Isosceles")
else:
print("Scalene")
#output:
#triangle is valid
#Isosceles
#-----------------------------------------------------------------------------------------------------------
#input:
for i in range(1,101):
print(i,end=" ")
#output:
#1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ........ 92 93 94 95 96 97 98 99 100
#Program No:28
for i in range(100,0,-1):
print(i,end=" ")
#output:
#100 99 98 97 96 95 94.........14 13 12 11 10 9 8 7 6 5 4 3 2 1
#Program No:28
#C. 1, 3, 5, 7........99
i=1
print(i,end=" ")
i=i+2
#output:
#1 3 5 7 9 11 13 15 17 19......79 81 83 85 87 89 91 93 95 97 99
#Program No:28
i=2
i=i*2
#output:
#2 4 8 16 32 64
#-----------------------------------------------------------------------------------------------------------
#Program No:29
#A
#B B
#C C C
#D D D D
#input:
#output:
for i in range(65,69):
for j in range(65,i+1):
print(chr(i),end=" ")
print()
#A
#B B
#C C C
#D D D D
#-----------------------------------------------------------------------------------------------------------
#Program No:30
#30. Print multiplication table of a number entered by the user. Validate that the number mu
#input:
num=int(input("enter number:"))
for i in range(1,11):
print(num,"x",i,"=",num*i)
#output:
#enter number:5
#5 x 1 = 5
#5 x 2 = 10
#5 x 3 = 15
#5 x 4 = 20
#5 x 5 = 25
#5 x 6 = 30
#5 x 7 = 35
#5 x 8 = 40
#5 x 9 = 45
#5 x 10 = 50
#-----------------------------------------------------------------------------------------------------------