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

Published: 01 May 2019
on channel: 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!')


On this page of the site you can watch the video online Unit 3 Lesson 2 - While Loops - Intro to Coding in Python with a duration of hours minute second in good quality, which was uploaded by the user Code Dog 01 May 2019, share the link with friends and acquaintances, this video has already been watched 160 times on youtube and it was liked by 1 viewers. Enjoy your viewing!