In this video we learn how to create while loops in Python.
This video is part of the Intro to Coding course, a free and open-source curriculum available for all classrooms to use. Intro to Coding was designed to introduce more schools and students into the computer technology fields. For more information visit https://github.com/isaiahkahler/intro...
Math Practice Example Program
----------------
import, initialize variable, and print
import random
done = False
print('welcome to math practice! pick an option.')
menu loop
while not Done:
print options
print('1 - practice addition')
print('2 - practice subtraction')
print('3 - practice multiplication')
print('4 - practice division')
print('5 - quit')
take input
choice = input()
addition problems
if choice == '1':
one = random.randint(1, 100)
two = random.randint(1,100)
answer = int(input(f'what is {one} + {two}? '))
if answer == one + two:
print('correct!')
else:
print(f'incorrect! the correct answer was {one + two}.')
subtraction problems
elif choice == '2':
one = random.randint(1, 100)
two = random.randint(1,100)
answer = int(input(f'what is {one} - {two}? '))
if answer == one - two:
print('correct!')
else:
print(f'incorrect! the correct answer was {one - two}.')
multiplication problems
elif choice == '3':
one = random.randint(1, 12)
two = random.randint(1, 12)
answer = int(input(f'what is {one} x {two}? '))
if answer == one * two:
print('correct!')
else:
print(f'incorrect! the correct answer is {one * two}.')
division problems
elif choice == '4':
one = random.randint(1, 12)
two = random.randint(1, 12)
product = one * two
answer = int(input(f'what is {product} ÷ {one}? '))
if answer == two:
print('correct!')
else:
print(f'incorrect! the correct answer is {two}.')
quit
elif choice == '5':
done = True
else:
print('not a valid menu option!')
In questa pagina del sito puoi guardare il video online Unit 3 Lesson 2 - While Loops - Intro to Coding in Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code Dog 01 maggio 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 160 volte e gli è piaciuto 1 spettatori. Buona visione!