[go: up one dir, main page]

0% found this document useful (0 votes)
12 views5 pages

Programs CS

Uploaded by

itssaara09
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)
12 views5 pages

Programs CS

Uploaded by

itssaara09
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/ 5

def sum(list):

length =len(list)
sum = 0
for i in range(length):
sum = sum + list[i]
return sum

def multiply(list):
length = len(list)
multiply = 1
for i in range(length):
multiply = multiply * list[i]
return multiply

def reverse(string):
length = len(string)
rev = ""
while length > 0:
length = length - 1
rev = rev + string[length]
return rev

name = input("give me a name")


print(reverse(name))

def palindrome(string):
length = len(string)
rev = ""
pal = False
while length > 0:
length = length - 1
rev = rev + string[length]
if rev == string:
pal = True
print("yes it is a palindrome")
else:
pal = False
print("no it is not a palindrome")

name = input("tell me ur name")


palindrome(name)

adult = 3
child = 2
transaction = 3
num_adults = int(input("how many adults"))
num_children = int(input("how many children"))
adult_price = num_adults * adult
children_price = num_children * child
num_tickets = int(input("how many tickets"))
ticket_price = num_tickets * transaction
total = ticket_price + children_price + adult_price
print(total)

a = int(input("tell me a number"))
b = int(input("tell me another number"))
if b > a:
a=a*b
print("your second number is larger than your first", a)
else:
if a < 5:
print("your first number is smaller than 5, it is", a)
else:
print("your first number is bigger than 5, it is", b)

suits = ['heart','diamond','clover','spade']
deck = []
for suit in suits:
for card in range(1,14):
deck.append(str(card)+suit)
print(deck)

animals =[['salmon','polluck','cod',],
['parrot','duck','wren',],
['camel','lion','tiger']]
from random import randint
a = randint(0,2)
b = randint(0,2)
print(animals[a][b])
if a == 0:
print('this is a fish')
elif a == 1:
print('this is a bird')
else:
print('this is a mammal')

#calculate the area ofa triangle


#area of triangle
def triangleArea(base,height):
triangleArea = base*height/2
return triangleArea
#main program
base = int(input('tell me the base of your triangle'))
height = int(input('tell me the height of your triangle'))
print('this is the are of your triangle',(triangleArea(base,height)))

#Dice face 5 problem


#subroutine for dice face 5
def output5():
print("ooooooooooo")
print("o o")
print("o # # o")
print("o # o")
print("o # # o")
print("o o")
print("ooooooooooo")
#main program
output5()

#Temperature converter problem


# Subroutine to convert Fahrenheit to Centigrade
def FtoC(F):
return (F-32) / 1.8
# Subroutine to convert Centigrade to Fahrenheit
def CtoF(C):
return (C * 1.8) + 32
#main program
C = 30
F = CtoF(C)
print(C,"degrees C is",F,"degrees F")

#characters problem
#subroutine for characters output
def digits():
return '0123456789'
def characters():
return 'abcdABCD@#!£'
def alphanumerics():
return '0123456789abcdABCD@#!£'
#main program
print('The digits are', (digits()))
print('The characters are', (characters()))
print('The characters are', (alphanumerics()))

#fishtank volume
def volume(litres,depth,height):
volume = litres*depth*height/1000
return volume
#main program
print(volume(10,10,10))

#microscopy problem
#subroutine to find magnification
def magnification(slideSize,actualSize):
magnification = slideSize*10000/actualSize
return magnification
#main program
print(magnification(2,10))

#carpet cost problem


#subroutine to find cost of a carpet
def cost(width,length,price):
price = 17*width*length
underlay = 3*width*length
grippers = width*2 + length*2
fitting = 50
cost = underlay+grippers+fitting+price
return cost
#main program
print(cost(7,6,17))

#energy bill problem


#subroutine to find the raw cost of energy usage
def rawCost(previous,current,calorific):
unitsUsed = current-previous
kWh = unitsUsed*1.022*calorific/3.6
energy = 2.84*kWh
return energy
#circle properties problem
#subroutines circle properties
def circleProperties(diameter,arcAngle):
radius = diameter/2
area = 3.14*radius**2
circumference = 3.14*diameter
arcLength = circumference*arcAngle/360
print('the radius is', radius, 'the area is', area, 'the circumference is', circumference, 'the
arcLength is', arcLength)
return arcLength
#main program
print(circleProperties(10,10))

#ball pit problem


#subroutine the volume of the ball pit
def volumeOfPit(radius,height):
volumePit == 3.14* radius**2*height
return volumePit
#subroutine the volume of the ball
def volumeOfBall(radius):
volumeBall == 4/3*3.14*radius**3
#subroutine to find the number of balls required to fill a pit
def numberOfBalls(volumePit,volumeBall):
numberOfBalls = volumePit/volumeBall*0.75
#main program
volumePit = volumeOfPit(1,0.2)
volumeBall = volumeOfBall(0.05)
print(numberOfBalls(volumePit, volumeBall))

passwords = [[],
[],
[]]
passwords[0].append('RasberryPiOS')
passwords[1].append('pi')
passwords[2].append('rasberry')
print(passwords)
changepassword = input('do you want to change your password?')
while changepassword == 'yes':
name = input('tell me your account name')
passwords[0].append(name)
username = input('tell me your username')
passwords[1].append(username)
password = input('tell me your password')
passwords[2].append(password)
changeagain = input('do you want to change your password again?')
if changeagain == 'no':
print(passwords)
break
else:
print('okay')
accountname = input('which account do you want to see the password for?')
location = (passwords[0].index(accountname))
print(location)

You might also like