diff --git a/05_challenge/05_challenge.py b/05_challenge/05_challenge.py new file mode 100644 index 0000000..0f9bdbd --- /dev/null +++ b/05_challenge/05_challenge.py @@ -0,0 +1,38 @@ +""" +We will use this script to teach Python to absolute beginners +The script is an example of reading the numbers from file in Python + +The problem is: +For all integers between 1 and 99 (include both): + # Read the input 3,5 and 99 from the input file + # print fizz for multiples of 3 + # print buzz for multiples of 5 + # print fizzbuzz for multiples of 3 and 5" +""" + +def fizzbuzz(max_num): + "This method implements FizzBuzz" + + # adding some redundant declarations on purpose + # we will make our script 'tighter' in one of coming exercises + three_mul = 'fizz' + five_mul = 'buzz' + with open('mifile.txt','r') as f: + print 'i have created' + num1 = int(f.readline()) + num2=int(f.readline()) + max_num = int(f.readline()) + + # Google for 'range in python' to see what it does + for i in range(1,max_num): + # % or modulo division gives you the remainder + if i%num1==0 and i%num2==0: + print(i,three_mul+five_mul) + elif i%num1==0: + print(i,three_mul) + elif i%num2==0: + print(i,five_mul) + +#----START OF SCRIPT +if __name__=='__main__': + fizzbuzz(100) diff --git a/05_challenge/05_filenametypo.png b/05_challenge/05_filenametypo.png new file mode 100644 index 0000000..0d0a2ce Binary files /dev/null and b/05_challenge/05_filenametypo.png differ diff --git a/05_challenge/05_readme.md b/05_challenge/05_readme.md new file mode 100644 index 0000000..e69de29 diff --git a/05_challenge/myfile.txt b/05_challenge/myfile.txt new file mode 100644 index 0000000..6891daa --- /dev/null +++ b/05_challenge/myfile.txt @@ -0,0 +1,3 @@ +3 +5 +99