-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpynative_exercises.py
More file actions
58 lines (49 loc) · 1.51 KB
/
pynative_exercises.py
File metadata and controls
58 lines (49 loc) · 1.51 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def exerciseOne():
'''print pyramid number'''
for i in range(10):
for j in range(i):
print(i, end=" ")
print()
def exerciseTwo():
'''Calculate the sum of all numbers from 1 to a given
number'''
sum = 0
givenNumber = input("Give a number: ")
for i in range(1, int(givenNumber) + 1):
sum += i
return sum
def exerciseThree():
'''Write a program to print multiplication table of a given number'''
n = input("Give a number: ")
for i in range(1, 11):
print(int(n) * i)
def exerciseFour():
'''Write a program to display those numbers from a list that will satisfy the following
conditions
* The number must be divisible by five
* If the number is greater than 500, then stop the loop.'''
arr = []
bool = True
while bool:
Userinput = int(input("Number: "))
if Userinput % 5 == 0 and Userinput < 500 and Userinput < 150:
arr.append(Userinput)
continue
elif Userinput > 150 and Userinput < 500:
continue
elif Userinput > 500:
bool = False
print(arr)
def exerciseFive():
UserInput = int(input("Range: "))
for i in range(UserInput, 0, -1):
for b in range(i, 0, -1):
print(b, end=" ")
print()
def exerciseSix():
UserInput = input("Numbers: ")
numbers = UserInput.split(" ")
currentIndex = len(numbers)
for i in range(len(numbers)):
print(numbers[currentIndex - 1])
currentIndex -= 1