Unit 3 Lesson 2 - While Loops - Intro to Coding in Python

Veröffentlicht am: 01 Mai 2019
auf dem Kanal: Code Dog
160
1

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!')


Auf dieser Seite können Sie das Online-Video Unit 3 Lesson 2 - While Loops - Intro to Coding in Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Code Dog 01 Mai 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 160 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!