0% found this document useful (0 votes)
17 views14 pages

Basics of Programming

BASICS OF PROGRAMMING

Uploaded by

tapoha6042
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)
17 views14 pages

Basics of Programming

BASICS OF PROGRAMMING

Uploaded by

tapoha6042
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/ 14

import random

for j in range(4):
p=0
n=0
avg=0
for i in range(20):

x=random.randint(-5,5)
print(i,x)
if x==0:
if p+n==0:
print("avg is 0")
break
elif x<0:
n+=1
avg=avg+x
elif x>0:
p+=1
avg=avg+x
print()
print("end",p,n,(avg/(p+n)))
print()

import random
l=(0,1,2)
for i in range(1,6):
print(f'Test case {i}')
x=random.choice(l)
y=random.choice(l)
if x==0 and y==1:
print("The computer is scissor. You are rock.You
won.")

if x==1 and y==2:


print("The computer is rock. You are paper.You
won.")

if x==2 and y==0:


print("The computer is paper. You are scissor.You
won.")

if x==1 and y==0:


print("The computer is rock. You are scissor.You
lost.")

if x==2 and y==1:


print("The computer is paper. You are rock.You
lost.")

if x==2 and y==0:


print("The computer is scissor. You are paper.You
lost.")

if x==0 and y==0:


print("The computer is scissor. You are scissor
too.It is a draw.")
if x==2 and y==2:
print("The computer is paper. You are paper too.It
is a draw.")
if x==1 and y==1:
print("The computer is rock. You are rock too.It is a
draw.")

import random
pre=0
cur=0
count=0
x=random.randint(-100,100)
pre=x
cur=x
for i in range(24):
x=random.randint(-100,100)
print(x)
if x==0:
break
if x>pre:
pre=x
count=1
if i==0:
pass
else:
if pre==cur:
count=count+1
else:
count=1

print()
print()
print(pre," is the largest with count of",count )

4
startfee=100000*((1+(8.5/100))**10)
tutionfee=startfee*((1+(8.5/100))**4)
print(f"After 10 years from now,your total tution fee
will be {tutionfee}")

5
import random

num1=random.randint(50,500)
num2=random.randint(50,500)

a=num1
b=num2
while b:
a,b=b,a%b
gcd_value=a

lcm_value=(num1*num2)//gcd_value
print(f"Numbers:{num1} and {num2}")
print(f"GCD:{gcd_value}")
print(f"LCM:{lcm_value}")
6

print("pattern a")
for i in range(1,7):
for j in range(1,i+1):
print(j,end="")
print()
print()

print("pattern b")
for i in range(1,7):
for j in range(1,7-i+1):
print(j,end="")
print()
print()
print("pattern c")
for i in range(1,7):
for j in range(1,7-i+1):
print(" ",end="")
for p in range(1,i+1):
print(i+1-p,end="")

print()
print()

print("pattern d")
for i in range(1,7):
for j in range(1,7-i+1):
print(j,end="")
print()
print()
7

import random
# x=random.randint(2,10)
x=7
print(x)
for i in range(0,x):
for j in range(1,x-i):
print(" ",end=" ")
for l in range(0,i+1):
print(2**l,end=" ")
for k in range(1,i+1):
print(2**(i-k),end=" ")
print()

8
import random
n=random.randint(4,10)
print(n)
for i in range(1,n+1):
for j in range(1,n+1-i):
print(" ",end=" ")
for l in range(1,i+1):
print(i+1-l,end=" ")
for k in range(2,i+1):
print(k,end=' ')
print()

9
loan = 10000
years = 1
annint = 7
mi = ((annint / 12) / 100)
pri = loan
mp = 865.26
intamt = pri * mi
amp = mp - intamt
bal = pri - amp
s=1

print("Payment InterestAmount Principal


Balance")
while bal > 1:
print(f'{s:<15} {round(intamt, 2):<25} {round(amp,
2):<15} {round(bal, 2):<15}')

intamt = round(intamt, 2)
amp = round(amp, 2)
bal = round(bal, 2)

intamt = bal * mi
amp = mp - intamt
bal = bal - amp
s += 1

10

import random

month_days=[31,28,31,30,31,30,31,31,30,31,30,31]
month_days_leap=[31,29,31,30,31,30,31,31,30,31,30,3
1]

months=["January","February","March","April","May",
"June","July","August","September","October","Novem
ber","December"]

year=random.randint(2001,2024)
first_day=random.randint(0,6)

print(f"Year: {year}, Starting Day: {first_day}")


days_in_months=month_days_leap if (year%4==0 and
year%100!=0) or (year%400==0) else month_days

for m in range(12):
print(f"\n{months[m]} {year}")
print("Sun Mon Tue Wed Thu Fri Sat")

start_day=first_day
for _ in range(start_day):
print(" ",end="")

for day in range(1,days_in_months[m]+1):


print(f"{day:3} ",end="")
start_day+=1
if start_day==7:
print()
start_day=0

first_day=start_day
11

for i in range(6,10001):
x=0
for j in range(1,i):
if i%j==0:
x=x+j
if x==i:
print(i)

You might also like