June 24th, 2013, 09:11 PM

Is my code for a hwk assigment right?
Code:
http://i.imgur.com/LgTvLbT.jpg
a_num=raw_input("Enter an integer for a:")
b_num=raw_input("Enter an integer for b:")
a_num=int(a_num)
b_num=int(b_num) sum=0
a_num=raw_input("Please enter an integer < b:")
a_num=int(a_num) print "Multiples of A that are less than B are:" for i in range(0,b_num,a_num):
print i sum=i+sum
print "Sum of these multiples:",sum
June 25th, 2013, 12:46 AM

Originally Posted by lunapt
Code:
http://i.imgur.com/LgTvLbT.jpg
a_num=raw_input("Enter an integer for a:")
b_num=raw_input("Enter an integer for b:")
a_num=int(a_num)
b_num=int(b_num) sum=0
a_num=raw_input("Please enter an integer < b:")
a_num=int(a_num) print "Multiples of A that are less than B are:" for i in range(0,b_num,a_num):
print i sum=i+sum
print "Sum of these multiples:",sum
Which part of this code finds out the multiples and prints them?
June 26th, 2013, 11:56 PM

With new lines and indentations in the right places your program works. Why do you get a value for a_num twice?
Try to find a different algorithm. Removing your intermediate print statements, and setting
b_num = 20000000
a_num = 2
my algorithm, O(1), runs sixty thousand times faster than your O(n) algorithm.
[code]
Code tags[/code] are essential for python code and Makefiles!