-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloops.py
137 lines (100 loc) · 2.49 KB
/
loops.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#if else if
marks=int(input("Value of X : "))
if marks >=90:
print("Distinction")
elif marks>=70:
print("FC")
elif marks>=50:
print("SC")
else:
print ("Fail")
# match statement similar to the if elif else conditions.
name = input("give me the name : ")
match name:
case "Cha" | "chw" | "che": # case with or statement "|"
print("Good")
case "chh":
print("Goodd")
case _:
print("Who???")
# while loop
i=int(input("Give the number of times you want to loop : "))
j=int(input("Give the end number : "))
if i<j:
while i<j:
print("Done")
i=i+1
else:
print("I is greater than J")
#while True if the while loop condition is true then it will break the loop and come out of the loop
while True:
n= int(input("Give me he number : "))
if n>0:
break
for _ in range(n):
print("Tryeee")
#printing a for loop
students=["Chan","Abhi","Chaaaaa","qpr","jar"]
for i in range(len(students)):
print(i+1, students[i])
#Dict which are in the values defined below.
students = {
"asda":"manvi",
"dhdt": "hggg",
"eetete":"sdr"}
print(students["asda"])
for student in students:
print(student,students[student],sep=', ')
#Printing the number of rows and columns
a = int(input("Number of Rows : "))
b = int(input("Number of Columns : "))
for i in range(a):
for j in range(b):
print("yes", end=' ')
print()
import sys
if len(sys.argv)<2:
sys.exit("Less arguments")
elif len(sys.argv)>2:
sys.exit("Too many arguments")
print("Hello,",sys.argv[1])
import sys
if len(sys.argv)<2:
print("less arguments")
sys.exit()
elif len(sys.argv) >2:
print("Too many arguements")
sys.exit()
print("Hello :", sys.argv[1])
#reverse a given number
n=int(input())
sum=0
while (n > 0):
digit=n%10
sum = sum*10 + digit
n=n//10
print(sum)
#file I/O
name=input("Give a Name: ")
print (f"Hello, {name}")
#Sort the given list using functions
names=[]
for _ in range(3): names.append(input("Gave a Name: "))
print(names)
temp=[]
for i in sorted(names):
temp.append(i)
print(temp)
#loops and printing based on the sorting techniquies
students=[{'name':'chandu','house':'cngalore'},
{'name':'gowda','house':'ahandapura'}]
houses=[]
for i in students:
if i['house'] not in houses:
houses.append(i["house"])
for hous in sorted(houses):
print(hous)
#generators
x=int(input("give the range value: "))
for i in range(x):
print("*"*i)