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

Python Assignment 1

Class assignment

Uploaded by

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

Python Assignment 1

Class assignment

Uploaded by

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

1.WAPtocheckwhetheranumberisoddorevenusingnestedif-else.

x = in t(in p u t("E nte r: "))


if x % 2 = = 0 :
p rin t( "E ve n ")
e ls e:
p rin t( "O d d ")

2.WAPtofindthegreatestnumberamong 3numbers.

x = in t(in p u t("E nte r x : "))


y= in t(in p u t("E n ter y: "))
z = in t(in p u t("E nte r z : "))
if x > y:
if x> z:
p rin t(x ,"is g re a te r")
els e :
p rin t(z ,"is g re a te r")
e ls e:
if y> z :
p rin t(y,"is g rea ter")
els e :
p rin t(z , "is g re ate r")

3. Calculate thegradeofastudentcontaining 5subjectsdependingon thefollowingconditions:


avg>=90 "O"
avg>=80 "E"
avg>=70 "A"
avg>=60 "B"
avg>=50 "C"
avg>=40 "D"
avg<40 "F"

s 1 = in t(in p ut("S u b jec t 1 : "))


s 2 = in t(in p ut("S u b jec t 2 : "))
s 3 = in t(in p ut("S u b jec t 3 : "))
s 4 = in t(in p ut("S u b jec t 4 : "))
s 5 = in t(in p ut("S u b jec t 5 : "))
a v g = (s 1 + s 2 + s 3 + s 4 + s 5 ) /5
p rin t("A v era g e :", a v g )
if a v g > = 9 0 :
p rin t( "O ")
e lif a v g > = 8 0 :
p rin t( "E ")
e lif a v g > = 7 0 :
p rin t( "A ")
e lif a v g > = 6 0 :
p rin t( "B ")
e lif a v g > = 5 0 :
p rin t( "C ")
e lif a v g > = 4 0 :
p rin t( "D ")
e lif a v g < 4 0 :
p rin t( "F ")

4. WAPtocheckwhetheranumberisprimeornot.

x = in t(in p u t("E nte r: "))


c=0
f o r i in ra n g e (1 ,x) :
if x% i= = 0 :
c =c+ 1
if c > 2 :
p rin t( "N o t p rim e ")
e ls e:
p rin t( "P rim e ")

5. WAP to print first n prime numbers.

n = in t(in p u t("E n te r h o w m a n y p rim e n u m b e rs ? \ n "))


c ount = 1
i= 2
k = ( i/ 2 )+ 1
p rin t("P rim e n u m b ers : ")
w h ile c o u n t < = n :
f la g = 0
f o r j in ra n g e (2 , i // 2 + 1 ):
if i % j = = 0 :
fla g = 1
b rea k
if fla g = = 0 :
p rin t(i)
c ount += 1
i += 1

6. WAP to print the prime factors of a number

d ef is _ p rim e (n ):
if n < = 1 :
re tu rn F a ls e
f o r j in ra n g e (2 , n / / 2 + 1 ):
if n % j = = 0 :
re tu rn F a ls e
re tu rn T ru e
n u m = in t(in p u t("E n ter a n y n u m b e r to p rin t P rim e fa c to rs : "))
p rin t(f"A ll Prim e F a c to rs o f {n u m } a re : ")
f o r i in ra n g e (2 , n u m + 1 ):
if n u m % i = = 0 :
if is _p rim e( i) :
p rin t(f"{i} ")

You might also like