Python Forum
multiples of 3, smaller than 100
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiples of 3, smaller than 100
#1
Hello!!
I have some tasks I need to do (not real HW, it's more like tasks to help me understand python from a classmate)
1. Code a program that writes multiples of 3 which is smaller than 100 in a file named multi.txt.
2. Code a program that adds multiples of 7 which is smaller than 100 in the file you created above.

Since I'm quite new to python I'm not really sure how to start with this? I know I probably need the range function and a loop... but how exactly do I write it?

I found this code, but it prints the sum which I don't need..
I've been googling all day but apparently it's too easy to find a solution for it lol

n = 101
sum = 0
for i in range(1,n,3):
    sum = sum + i
print (sum)
Can someone please help me out..
Reply
#2
your print statement needs to be indented to same level as sum = ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python - Analyzing for even intergers and multiples jhenehan 2 4,037 Sep-04-2017, 12:10 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020