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

Coding

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)
24 views

Coding

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
You are on page 1/ 20

# -*- coding: utf-8 -*-

"""AU2040261 Divyashree jadeja

Automatically generated by Colaboratory.

Original file is located at

https://colab.research.google.com/drive/1ZK3MHz_tUUIx2oRu4QbrdOOjn4o7whdQ

"""

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:1

#1. Write a Python program to read and print your name

#input:

name=input("enter your name:")

print("hello",name)

#enter your name:Divyashree jadeja

#hello Divyashree

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:2

#2. Write a Python program to print your ID – Card

#input:

n=input("enter youe name:")

m=input("enter your roll number:")

s=input("enter your university:")

print("Name:",n ,"\nroll number:", m ,"\nuniniversity:",s)

#output:

#enter youe name:Divyashree


#enter your roll number:AU2040261

#enter your university:Ahmedabad university

#Name: Divyashree

#roll number: AU2040261

#uniniversity: Ahmedabad university

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:3

#3. Write a Python program to input a number and check whether the entered number is even or
not

#input:

n=int(input("enter your number:"))

if n%2 == 0:

print("your number is even")

else:

print("your number is odd")

#output:

#enter your number:6

#your number is even

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:4

#4. Write a Python program to check whether a number is divisible by 5 or not.

#input:

n=int(input("enter your number:"))

if n%5 == 0:

print("your number is divisible by 5")


else:

print("your number is not divisible by 5")

#output:

#enter your number:15

#your number is divisible by 5

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:5

#5. Write a Python program to read a month number and print corresponding month name

#input:

n=int(input("enter month number:"))

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:

#enter month number:4

#april

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:

print("triangle is not valid")

#output:

#enter angle1:60

#enter angle2:60

#enter angle3:60

#triangle is valid

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:8

#8. Write a Python program to calculate the Area of a Triangle.

#input:

base=int(input("enter base of triangle:"))

height=int(input("enter height of triangle:"))

area=base*height/2

print("area of trianglr is:",area,"m^2")

#output:

#enter base of triangle:3

#enter height of triangle:6

#area of trianglr is: 9.0 m^2

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:"))

if age >= 18:

print("person is eligible to vote ")

else:

print("person is not eligible to vote")

#output:

#enter your age:13

#person is not eligible to vote

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:10

#10. Write a Python program to Generate and print a Random Number.

#input:

import random

print( random.random())

#output:

#0.9662836770371147

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:11

#11. Write a Python program to Convert Celsius to Fahrenheit.

#input:

cel=int(input("enter tempreture in celsius:"))

F=9/5*cel + 32

print("tempreture in fehrenheit is:",F)

#output:

#enter tempreture in celsius:5


#tempreture in fehrenheit is: 41.0

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:12

#12. Write a Python program to make a Simple Calculator.

#input:

n1 = float(input("Enter n1: "))

op = input("Enter math oprator: ")

n2 = float(input("Enter n2: "))

if op == '+':

print(n1 , op , n2 , "=" , n1 + n2)

elif op == '-':

print(n1 , op , n2 , "=" , n1 - n2)

elif op == '*':

print(n1 , op , n2 , "=" , n1 * n2)

elif op == '/':

print(n1 , op , n2 , "=" , n1 / n2)

else:

print("entered oprator is not valid")

#output:

#Enter n1: 5

#Enter math oprator: *

#Enter n2: 5

#5.0 * 5.0 = 25.0

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:13
#13. Write a Python program to print the sum of first 10 numbers.

#input:

i=1

sum=0

while i <= 10:

i=i+1

sum=sum+i

print("sum is :",sum,end=" ")

#output:

#sum is : 2 sum is : 5 sum is : 9 sum is : 14 sum is : 20 sum is : 27 sum is : 35 sum is : 44

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:"))

if n1>n2 and n1>n3:

print("the greater number" , n1)

elif n2>n1 and n2>n3:

print("the greater number" , n2)

else:

print("the greater number" , n3)

#output:

#enter number:6

#enter number:9

#enter number:3
#9

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:

#sum of odd numbers till N

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

#sum 3 sum 8 sum 15 sum 24 sum 35 sum 48

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:15

#15. Write a program to find the sum of odd numbers and even numbers from 1 to N, N entered

#input:

#sum of even numbers till N

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

#sum 2 sum 6 sum 12 sum 20 sum 30 sum 42

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:16

#16. Create a converter that will convert a distance in meters to feet and inches.

#input:

distance=int(input("enter your distance in meters:"))

feet = distance*3.281

print("your distance in feet:",feet)

#output:

#enter your distance in meters:9

#your distance in feet: 29.529

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:16

#16. Create a converter that will convert a distance in meters to feet and inches.

#input:

distance=int(input("enter your distance in meters:"))

inches= distance*0.0254

print("your distance in feet:",inches)

#output:

#enter your distance in meters:9

#your distance in feet: 0.2286


#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:

char=input("enter any character:")

if char=='a' or char=='e' or char=='i' or char=='o' or char=='u':

print("your character is a vowel")

else:

print("your character is a consonant")

#output:

#enter any character:h

#your character is a consonant

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:18

#18. Write a program to check whether a character is uppercase or lowercase alphabet

#input:

str=input("enter your name:")

if str.isupper():

print("character is in uppercase")

else:

print("character is in lowercase")

#output:

#enter your name:vishwa

#character is in lowercase
#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:19

#19. Write a program to accept two numbers and one mathematical operator. Calculate and display
appropriate answer as shown below:

#input:

n1=int(input("enter your number:"))

n2=int(input("enter your number:"))

op = input("Enter math oprator: ")

if op == '+':

print(n1,op,n2,"=",n1+n2)

#enter your number:3

#enter your number:4

#7

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:

num = input("Enter a number: ")

# initializing sum to zero

sum = 0

for i in num:

sum += int(i)

print("The sum of digits of number is",sum)

#Enter a number: 4567

#The sum of digits of number is 22


#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:"))

if year%4==0 or year%100==0 and year%400==0:

print("year is leap year")

else:

print("year is not leap year")

#output:

#enter year:2012

#year is leap year

#------------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:22

#if the int is 12345, the output shall be "5 4 3 2 1", with a space separating the digits.

#input:

num = int(input("Enter a number with multiple digit: "))

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

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:23

#23. Accept a number N from the user and print the first N elements of the Fibonacci series.

#input:

n=int(input("enter your number:"))

x=0

y=1

z=0

while z<=n:

print(z,end=" ")

x=y

y=z

z=x+y

#enter your number:16

#0 1 1 2 3 5 8 13

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:24

#24. Calculate the area of triangle given its three sides. The formula or algorithm used is:

#sqrt(s(s – a)(s – b)(s – c)), where s = (a + b + c) / 2 or perimeter / 2

#input:

a=float(input("enter side of triangle:"))

b=float(input("enter side of triangle:"))

c=float(input("enter side of triangle:"))


s=a+b+c / 2

area = (s*(s-a)*(s-b)*(s-c)) ** 0.5

print("the semi perimeter of triangle:",s)

print("the area of triangle:",area)

#output:

#enter side of triangle:4

#enter side of triangle:8

#enter side of triangle:2

#the semi perimeter of triangle: 13.0

#the area of triangle: 80.21845174272562

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:25

#25. Write a program that take input of 3 subjects marks out of 150. Count the percentage. P

#input:

sub1=int(input("enter your marks in subject1:"))

sub2=int(input("enter your marks in subject2:"))

sub3=int(input("enter your marks in subject3:"))

percentage= sub1 + sub2 + sub3 / 150 * 100

if percentage >= 70:

print("DISTINCTION")

elif percentage >= 60 and percentage <= 69:

print("FIRST CLASS")

elif percentage >= 50 and percentage <= 59:

print("SECOND CLASS")

elif percentage >= 40 and percentage <= 49:

print("PASS CLASS")

elif percentage < 40:

print("fail")
#output:

#enter your marks in subject1:20

#enter your marks in subject2:10

#enter your marks in subject3:10

#fail

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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:

math=int(input("enter your marks of maths:"))

phy=int(input("enter your marks of physics:"))

chem=int(input("enter your marks of chemistry:"))

percentage1= math / 70 * 100

percentage2= phy / 70 * 100

percentage3= chem / 70 * 100

#i) Mathematics >= 50%, Physics >= 45%, Chemistry >= 60% Overall Percentage >= 65%

if percentage1 >= 50 and percentage2 >= 45 and percentage >= 60:

print("student is eligible for admission based on the following criteria")

else:

print("student is not eligible for admission based on the following criteria")

#output:

#enter your marks of maths:20

#enter your marks of physics:30

#enter your marks of chemistry:20

#student is not eligible for admission based on the following criteria

#-----------------------------------------------------------------------------------------------------------
#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:

a=int(input("enter side lenght of triangle:"))

b=int(input("enter side lenght of triangle:"))

c=int(input("enter side lenght of triangle:"))

if a + b > c:

print("triangle is valid")

else:

print("triangle is not valid")

if a == b == c:

print("Equilateral")

elif a == b or b == c or a == c:

print("Isosceles")

else:

print("Scalene")

#output:

#enter side lenght of triangle:6

#enter side lenght of triangle:6

#enter side lenght of triangle:4

#triangle is valid

#Isosceles

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja


#Program No:28

#A. 1, 2, 3, 4 ........ 100 print

#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

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:28

#B. 100, 99, 98.......1

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

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:28

#C. 1, 3, 5, 7........99

i=1

while i <= 99:

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

#Roll number:AU2040261 Name:Divyashree jadeja

#Program No:28

#D. 2, 4, 8, 16, 32, 64

i=2

while i <= 64:


print(i,end=" ")

i=i*2

#output:

#2 4 8 16 32 64

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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

#-----------------------------------------------------------------------------------------------------------

#Roll number:AU2040261 Name:Divyashree jadeja

#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

#-----------------------------------------------------------------------------------------------------------

You might also like