"""
Python Intro Assignment #2
name
student number
"""
#Ask the user for a radius of a circle
user_radius =(input("What is the radius?"))
#Convert the given radius to a floating point
radius= float(user_radius)
#make a variable called pi
pi = 3.1415
#Calculate the area of the circle using exponents
area =(pi*(radius**2))
#diaplay the area of the circle to the user
print("The area of the circle is", area)
#Mill's method
word= input("Please enter yout word")
index= len(word)-1
reverse= ''
while (index>-1):
reverse=reverse+word[index]
index=index-1
print (reverse)
#mr's method
word= input("Please enter yout word")
index=0
reverse=''
while index< len(word):
reverse=word[index]+ reverse
index=index+1
print("reverse: ",reverse)
import random
#Create a list
guesslist = ['grape', 'orange', 'chloroplast', 'ribosome', 'lipstick']
chance = 3
score = 0
print (guesslist)
while chance != 0:
random_item = random.choice(guesslist)
user_input = input("Please guess a word: ")
if user_input == random_item:
print ("That's correct!")
score = score + 100
print ("Score:", score)
else:
if user_input not in guesslist:
print ("Sorry, that isn't even in the list!")
chance = chance - 1
print ("Chance Remaining:", chance)
else:
print ("Sorry, wrong choice!")
chance = chance - 1
print ("Chance Remaining:", chance)
if chance == 0:
print ("The word was", random_item)
print ("The score is", score)
|
print()
|
Show information that you want on the screen
|
|
int()
|
Change number to be number integer
|
|
float()
|
Change number to be decimal number
|
|
input()
|
Gain information from user
|
|
str()
|
A list of number, letter and symbols
|
|
len()
|
The length of the string
|
|
#
|
Comment, no effect
|
|
import random + random.choice()
|
pick random item in the list
|
|
==
|
equal to
|
|
!=
|
no equal to
|
|
<
|
less than
|
|
>
|
more than
|
|
<=
|
less than or equal
|
|
>=
|
more than or equal
|
|
%
|
Modulo, Find the remainder
|
|
string + string
|
combine together
|
|
string + number
|
CRASH
|
|
number + number
|
addition (Math)
|
|
string * number
|
combine that string
|
|
string* string
|
CRASH
|
|
number * number
|
Multiply (Math)
|
|
number ** number
|
Exponent (Math)
|
|
string ** number
|
CRASH
|
|
Variable
|
Hold a value and can be change
|
|
String
|
A list of character such as number, letter and symbols
|
|
Integer number
|
Whole number/counting number
|
|
Floating point
|
The number in decimal
|
number = int(input("Enter number: "))
if number>0:
print(number, "is positive")
print(number,"is negative")
number= [3, 2, 77, 32, 9, 8, 31]
largest = 0
for value in number:
if number> largest:
largest = number
print (largest)
mylist = [ ]
for number in range(5):
mylist.append(input("Enter value: "))
#write a program that converts a number to binary
#get a number from the user
user_number = int(input("Enter a number to convert to binary: "))
#while loop
#
while (user_number >0): #the number is greater than 0)
remainder =
binary_string =
binary_string =
#after the loop print the binary string
print ("Binary string is", binary_string)
#expected output - 5 =101
#expected output - 3 =11
#expected output - 2 =10
#lists
shoppinglist = ['phone', 'battery', 'charger']
for item in shoppinglist:
print (item)
for number in range (1, 10):
print (number)
for number in range(5):
print (number)
##################################################
#lists
fruits= []#an empty list
for number in range(5):
user_fruit= input("Please enter a fruit")
fruits.append(user_fruit)
print ("size of fruit list is", len(fruits))
for fruit in fruits:
print("Fruit: ", fruit)
number= int(input("Enter number: "))
if number%2 ==0:
print (number, "is even num")
else:
print (number, "is odd num")
def AreaOfCircle(radius):
A=3.14*radius*radius
return A
num= int(input("Enter a radius: "))
x= AreaOfCircle(num)
print(x)
1= !
2= !!
!!
3= !!!
!!!
!!!
for number in mylist:
print (number)
mylist =[ ]
while True:
value = input("Enter value: ")
if value == "*"
break
else:
mylist.append(value)
print (mylist)
number= int(input("What's your number?")
while(number>=1):
print(number)
number=number-1
convert= int(input("What do you want to convert to?")
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.