Tag Archives: python

Refactor: Highest and Lowest Number

Python Original: numbers_list = [] highest = 0 lowest = None print “Please enter a number: ” numbers = raw_input(“> “) try: numbers = int(numbers) except: numbers = -1 numbers_list.append(numbers) def test(next_number): try: next_number = int(next_number) except: next_number = num new_number() else: numbers_list.append(int(next_number)) def done(): print “Here’s a list of the numbers you entered: %r” … Continue reading Refactor: Highest and Lowest Number

Highest and Lowest Number

It took me most of the day but it’s done. This is the largest Python program I’ve EVER written from scratch. Write a program that repeatedly prompts a user for integer numbers until the user enters ‘done’. Once ‘done’ is entered, print out the largest and smallest of the numbers. If the user enters anything … Continue reading Highest and Lowest Number

Coding Challenge – Multiples of 3 and 5

Python ”’ Multiples of 3 and 5: Example: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Challenge: Find the sum of all the multiples of 3 or 5 below 1000. ”’ multiples_of_3 = … Continue reading Coding Challenge – Multiples of 3 and 5

Coding Challenge – Factors of a Number

# Write a program which prints the factors of a given number. # Example – Input: 6 Output: 1, 2, 3, 6 # Example – Input: 10 Output: 1, 2, 5, 10 # version 1: the code works print “This program is designed to return all the factors of a number.” print “Factors are the … Continue reading Coding Challenge – Factors of a Number

Coding Challenge – 99 Bottles of Beer

Python # version 1 bottles_of_beer = 100 for each_bottle in range(99): bottles_of_beer = bottles_of_beer – 1 bottles_left = bottles_of_beer -1 print “%r bottles of beer on the wall,\n %r bottles of beer.\n Take 1 down, pass it around,\n %r bottles of beer on the wall.” % (bottles_of_beer, bottles_of_beer, bottles_left) # version 2 bottles_of_beer = 100 … Continue reading Coding Challenge – 99 Bottles of Beer