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

Publicado el: 01 mayo 2019
en el canal de: 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!')


En esta página del sitio puede ver el video en línea Unit 3 Lesson 2 - While Loops - Intro to Coding in Python de Duración hora minuto segunda en buena calidad , que subió el usuario Code Dog 01 mayo 2019, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 160 veces y le gustó 1 a los espectadores. Disfruta viendo!