-
Notifications
You must be signed in to change notification settings - Fork 0
/
Looping 1.py
executable file
·40 lines (34 loc) · 936 Bytes
/
Looping 1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import math
q = int(input("Which Question: "))
if q == 1:
number = input("Enter a number: ")
number = eval(number)
print("All squares less than ", number, ":")
k = 0
while (k ** 2 < number):
print(k ** 2, end = ' ')
k = k + 1
k = 0
print("\n\nAll positive numbers that are divisible by 10 and less than ", number, ":")
while (k * 10 < number):
if k * 10 > 0:
print(k * 10, end = ' ')
k = k + 1
k = 0
print("\n\nAll powers of 2, less than ", number, ":")
while (2 ** k < number):
print(2 ** k, end = ' ')
k = k + 1
if q == 2:
k = 0
for x in range(2, 101):
if x % 2 == 0:
k += x
print("Sum of all even numbers from 2 to 100: ", k)
k = 0
for x in range(1, 101):
k += x ** 2
print("\n\nSum of all squares 1 to 100: ", k)
if q == 3:
for i in range(1, 10, 2):
print(i)