Functionint() | Change number to be number integer | float() | Change number to be decimal number | str() | A list of number, letter and symbols | print() | Show information that you want on the screen | len() | The length of the string | # | Comment, no effect | import random + random.choice | pick random item in the list |
Reverse Wordwhile True:
word = input("Please enter a word")
index = 0
reverse = ' '
while int(index) < len(word):
reverse = word[index] + (reverse)
index = int(index) + 1
print ("Reverse: ", reverse)
|
Sort word per linemystr = "Hello"
letter_num = 0
while letter_num < len(mystr):
print (mystr[letter_num])
letter_num = letter_num + 1
|
Circle area"""
Python Intro Assignment #2
name
student number
"""
#Ask the user for a radius of a circle
user_radius = input("What is a radius of a circle?")
#Convert the given radius to a floating point
radius = float(user_radius)
#Make a variable called pi
pi = float(3.1415)
#Calculate the area of the circle using exponents
area = pi(radius*2)
#Display the area of the circle to the user
print ("The area of the circle is", area)
|
| | Additionstring + string | Combine together | string + number | Crash | number + number | Math - addition |
Multiplication and Exponentsstring * number | Combine that string | string * string | Crash | number * number | Math - multiply | string ** string | Crash | number ** number | Math - exponent | string ** number | Crash |
Convert to Binaryuser_number = ' '
while user_number != '0':
user_number = input("Enter a number to convert to binary")
number = int(user_number)
binary_string = ''
while (number > 0):
remainder = number%2
binary_string = str(remainder)+ binary_string
number = number//2
print ("Binary string is",binary_string)
|
Decimal to Binary
user_number = ' '
while user_number != '0':
user_number = input("Enter a number to convert to binary")
number = int(float(user_number))
binary_string = ''
while (number > 0):
remainder = number%2
binary_string = str(remainder)+ binary_string
number = number//2
print ("Binary string is",binary_string)
Print namename = "jirat PRASERTMAK"
print (name.upper()) -----------> JIRAT PRASERTMAK
print (name.lower()) -----------> jirat prasertmak
print (name.capitalize()) -----------> Jirat prasertmak
print (name.title()) -----------> Jirat Prasertmak
|
| | Math== | equal to | != | no equal to | < | less than | > | more than | <= | less than or equal | >= | more than or equal | % | Modulo, find the remainder |
Vocabularyvariable | Hold a value and can be changed | syntax | Grammar or structure of language | modulo | Find the remainder | boolean | True or false | floating point | The number in decimal |
Countdown Machineuser_number = input("What number do you want to count down? ")
number = int(user_name)
countdown-string = ''
while number > 0
countdown_number = countdown_string + str(number) + " "
number = number - 1
#print(number)
print (countdown_string)
|
Guess word gameimport random
#Create a list
guesslist = ['vesicle', 'lysosome', 'chloroplast', 'ribosome', 'vacuole']
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)
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment