You are on page 1of 2

#%% sum of factorials

n=int(input("enter no "))
def sum_fact(n):
p=1
s=0
for i in range(1,n+1):
p=p*i
s=s+p
return s
print(sum_fact(n))
#%%
import random
n=int(input("enter the number"))
def func(n):
c=0
d=int(c-1)
f=int(c+1)
for i in range(n+1):
c=c+i
c=int(c)
for j in range(10**d,10**f):
return int(random.choice(j))
print(func(n))
#%%
import random
n=input("enter a number ")
def func(n):
y=len(n)
h=int(y)
return random.randint(10**(h-1),10**h-1)
print(func(n))
#%% 1. Write a function generate() which will accept an integer as argument
,generates a random number with exactly �n� digits and returns it. Accept a
number �n� from the user and pass it to the generate function . If �n� is
not passed to the function during the call then the function should return a 3
digit number generated randomly.
import random
n=input("enter a number ")
def func(n):
y=len(n)
h=int(y)
if n=="":
return random.randint(10**(3-1),10**3-1)
else :
return random.randint(10**(h-1),10**h-1)
print(func(n))
#%% RF ? power which will calculate the power of x and returns it(not to use
math.pow())? power which will calculate the power of x and returns it(not to
use math.pow())
x=int(input("enter the number "))
n=int(input("power to which it is raised "))
def power(x,n):
return x**n
print(power(x,n))
#%% ? factorial which will calculate the factorial of the given number and
returns it
def fact(x):
p=1
for i in range(2,x+1):
p=p*i
return p
print(fact(x))
#%% CREATE( ) Accept values from the user to store the noon temperature of each
day of the week for a month. The key for the dictionary would be the week
number(1,2,3,4) and values would be a list of 7 temperatures for each week
d={}
n=int(input("enter the number of week numbers "))
for i in range(n):
k=int(input("enter the week number "))
v=int(input("enter the noon temperature "))
d[k]=v
#%% CHECK( ) Checks the dictionary and prints each weeks average temperature. It
also should print the hottest and coolest day of the month.
d={}
s=0
n=int(input("enter the number of week numbers "))
for i in range(n):
k=int(input("enter the week number "))
v=int(input("enter the noon temperature "))
d[k]=v
for j in d.values():
s=s+j
l=d.values()
l=list(l)
l.sort()
print("the average temperature is",s//n)
print("the hottest temperature is ",l[-1])
print("the coldest temperature is ",l[0])
#%%
l=[2,4,9,13,21]
def prime(l):
for j in range(len(l)):
for i in range(1,j):
if j%i==0:
print("1")
else:
print("0")
print(prime(l))
#%%
l=[1,2,3,4]
for i in range(len(l)):
l[i]=l[i]+1
print(l)
#%%
l=[1,2,3,4]
def convert(l):
for i in range(0,len(l)):
i=int(i)
l[i]+=1
return l
print(convert(l))
#%%

You might also like