-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor loops.py
More file actions
78 lines (51 loc) · 1.6 KB
/
for loops.py
File metadata and controls
78 lines (51 loc) · 1.6 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# For loop practical questions
# Print num from 1 to 5 using for loop
# for i in range(1, 11):
# print(i,end=" ")
# # Print name upto 10 times using for loop
# for i in range(1, 11):
# print("Muhammad Talha", )
# # Print num from 1 to 5 using for loop
# for i in range(1, 3):
# print((1,2,3,4,5,6,7,8,9,10),end=" , ")
# print squares of number from 1 to 5
# for i in range(1, 6):
# print(i ** 2, end=" ")
# # print all even number from 1 to 10
# for i in range(1, 11):
# if i % 2==0:
# print(i, end=" ")
# print("loop has ended")
# calculate sum of number b/w 1 to 10
# sum=0
# for i in range(1, 11):
# sum+=i
# print(f"sum is {sum}")
# reverse the word python using for loop
# word="Python"
# for i in range(len(word)-1, -1, -1):
# print(word[i], end="")
# write a prograam to count vowels in word "Education"
# vowels="aeiou"
# word="education"
# count=0
# for chr in word:
# if chr in vowels:
# count+=1
# print(f"Total vowels in {word} is {count}")
# calculate factorial of a given number
# number=int(input("Enter a number"))
# fact=1
# for i in range(1, number+1):
# fact*=i
# print(f"factorial of {number} is {fact}")
# print fiabonnaci sequence upto 10 terms
n_terms = 10
first = 0
second = 1
print("Fibonacci sequence up to 10 terms:")
for i in range(n_terms):
print(first, end=" ")
next_term = first + second
first = second
second = next_term