Homework:
Write a while loop with these conditions:
Variable num starts at 0
Increments by 3 for a multiple of 2
Increments by 5 for a multiple of 3
Increments by 7 for a multiple of 5
Else, increment by 1
(For numbers like 30, a multiple of 2, 3, and 5, just let it increment thrice.)
num ends at 50
Write a for loop that reverses a string.
Write a while loop that prints all numbers from 1 to 50 except multiples of 4.
Resources: Class slides: https://docs.google.com/presentation/d/12rWL4PsRGKQ8NNUjlfhZL2R8WsSt6vfex4KB7vGWAJI/edit#slide=id.g15d5b893d3d_0_140
Class code: https://replit.com/@ShravyaS/IntrotoPython-Class4#main.py Contact info: shravyassathish@gmail.com (mentor) kingericwu@gmail.com (TA) felixguo41@gmail.com (TA)
1. num = 0
while(num < 50):
if num%2 == 0:
num = num+ 3
if num%3 == 0:
num= num+ 5
if num%5 == 0:
num=num+7
else:
num=num+ 1
print(num)
2.idk
3.num = 0
while (num <= 50):
if num % 4 == 0:
continue
num = num + 1
print(num)
1. num=0
while num <50 :
if num%2==0:
num=num+3
elif num%3==0:
num=num+5
elif num%5==0:
num=num+7
else:
num=num+1
print(num)
2. I couldn't find a solution
3.
num=1
while num<=50:
if num%4!=0:
print(num)
num=num+1
else:
num=num+1
continue
1.
number = 0
while (number == 50):
temp = number
if temp % 2 == 0:
number += 3
if temp % 3 == 0:
number += 5
if temp % 5 == 0:
number += 7
if temp % 2 != 0 and temp % 3 != 0 and temp % 5 != 0:
number += 1
2.
string = "My name is Ethan Xiong"
newstring = ""
for i in range(0, len(string)):
newstring = newstring + string[len(string) - i - 1]
print(newstring)
3.
for i in range(1, 51):
if i % 4 != 0:
print(i)
#1
num = 0
while num <= 50:
if num % 2 == 0:
num += 3
if num % 3 == 0:
num += 5
if num % 5 == 0:
num += 7
elif (num % 2 != 0) and (num % 3 != 0) and (num % 5 != 0):
num += 1
#2
string = input("Enter a string: ")
result = ""
for x in range(len(string) - 1, -1, -1):
result += string[x]
print(result)
#3
num = 1
while num <= 50:
if num % 4 != 0:
print (num)
num += 1
print("Part 1")
num = 0
while num < 51:
print(num)
nextnum = 0
if num % 2 == 0:
nextnum += 3
if num % 3 == 0:
nextnum += 5
if num % 5 == 0:
nextnum += 7
elif num % 2 != 0 and num % 3 != 0:
nextnum += 1
num += nextnum
string = input("\n\n\nPart 2: Please enter a string to reverse: ")
reversedstring = ""
for i in string:
reversedstring = i + reversedstring
print(reversedstring + "\n\n\n\nPart 3:")
j = 0
while j <= 49:
j += 1
if j % 4 == 0:
continue
print(j)
1) num=0
while (num<51):
if num%2==0:
print(num)
num+=3
if num%3==0:
print(num)
num+=5
if num%5==0:
print(num)
num+=7
else:
print(num)
num+=1
2) I could not find the solution
3) num=0
while (num<51):
num+=1
if num%4==0:
continue;
print(num)
1) num=0
while (num<51):
if num%2==0:
print(num)
num+=3
if num%3==0:
print(num)
num+=5
if num%5==0:
print(num)
num+=7
else:
print(num)
num+=1
2) I couldnt find answer
3) num=0
while (num<51):
num+=1
if num%4==0:
continue;
print(num)
1) num=0
while (num<51):
if num%2==0:
print(num)
num+=3
if num%3==0:
print(num)
num+=5
if num%5==0:
print(num)
num+=7
else:
print(num)
num+=1
2) I couldn't seem to find the solution to this problem
3) num=0
while (num<51):
num+=1
if num%4==0:
continue;
print(num)