Repository navigation
Expand file tree
/
Copy pathloopques.py
More file actions
59 lines (57 loc) · 1.89 KB
/
Copy pathloopques.py
File metadata and controls
59 lines (57 loc) · 1.89 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
58
59
#counting positive numbers
numbers = [1,2,-3,7,-5,8]
positive_num_count = 0
for num in numbers:
if num>0:
positive_num_count+=1
print('final count', positive_num_count)
----------------------------------------------------------------------------------------------------------------------------------------------------
#sum of even numbers
numbers = [1,2,3,4,5,6,7,8,9,10]
even_count = 0
for num in numbers:
if num%2==0:
even_count+=num
print('final result', even_count)
----------------------------------------------------------------------------------------------------------------------------------------------------------
#multiplication table print
numbers = int(input("give the number:"))
for i in range(1,11):
if i==5:
continue
print('numbers','x','i',"=", numbers*i)
------- --- -----------------------------------------------------------------------------------------------------------------------------------------------
#reverse a string
char = 'python'
reverse_char =''
for i in char:
rverse_char = char+reverse_char
print(reverse_char)
------------------------------------------------------------------------------------------------------------------------------
#factorial calculator
number = 10
factorial =1
while number>1:
factorial = factorial*number
number-=1
print(factorial)
-----------------------------------------------------------------------------------------------------------------------
#prime number cheacker
number = 29
is_prime = True
for i in range(2,number):
if number%i==0:
is_prime =False
break
print(is_prime)
-------------------------------------------------------------------------------------------------------------------------------
#exponetial backoff
import time
wait_time = 1
max_retrives = 5
attempts = 0
while attempts<max_retrives:
print('attempt', 'attempt+1', 'wait_time')
time.sleep(wait_time)
wait_time*=2
attempts+=1