# -*- coding: utf-8 -*- """ Created on Wed Feb 13 11:53:32 2019 @author: achuang """ def count_to_10(): """ Print out the Numbers 0 to 10, each on a new line. """ count = 0 while(count <= 10): print(str(count)) count = count + 1 def loop_to_10(): """ Using a while loop, print out the numbers 1 to 10 """ count = 0 while(count <= 10): print(str(count)) count = count + 1 def break_python(): """ Create an infinute loop. How many ways can this be done? """ on_off = 0 while not(on_off == "y"): print("close the loop? y/n") on_off = input() def loop_to_N(): """ The user inputs an integer, print out all the numbers from 0 to it. Bonus: Check for valid input Should we have a maximum limit? """ print("Enter a number, I will add up to it!") number = input() count = 0 while (int(count) <= int(number)): print(count) count = count + 1 def sum_of_N(): """ The user inputs a integer. Add all numbers from 1 to that number. Eg. input: 5 Output: 1+2+3+4+5 = 15 Bonus:check for valid input Challenge: How do you know this code works? Can you prove it? """ print("Enter a number, I will add together all numbers leading up to it") number = input() total = 0 count = 0 while (int(count) <= int(number)): print(count) total = count + total count = count + 1 if(int(count) >= int(number)): print(count) total = count + total print(str(total)) break def password_Entry(): """ Create a password. Ask the user for a password and loop until he enteres it correctly or has used 3 attempts. """ password = 0 password_guesses = 0 while(int(password_guesses) <= 3): print("please enter your password") password = input() if(str(password) == "Incorrect!"): print("Welcome!") break else: print("Your password is Incorrect!") password_guesses = password_guesses + 1 def fraction_pattern(): """ Create a program to add 1/2 + 1/3 + 1/4..... to a maximum limit you define as "n". Make n a user input. What is the number after looping 3000 times? what about 1,000,000? """ from fractions import Fraction number = input() total = 0 count = 0 while (int(count) <= int(number)): print(count) total = count + total count = count + 1 if(int(count) >= int(number)): print(count) total = count + total print(str(total)) break