### Thread: Is my code for a hwk assigment right?

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2013
Posts
12
Rep Power
0

#### 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
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2013
Location
/dev/null
Posts
164
Rep Power
19
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?
3. 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.