-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic python
219 lines (181 loc) · 5.91 KB
/
basic python
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# print("1. Concatenation of string")
# firstName= "Sudip "
# LastName ="Pradhan"
# print(type(firstName))
# name= firstName+LastName
# print(name)
# print("\n2. Slice Operator")
# slice operator as string
name= "SudipIsGoodBoy"
print(name[0:5]) #Output = Sudip
print(name[0: :3]) # Output=Sisoo
#slice operator as list
list = [2,0,2,3,0,5,2,3]
print(list[2::2]) #Output = [2,0,2]
# print("\n3. String function")
# name= "My name is Sudip Pradhan. I live in Kathmandu with my brother."
# doubleSpace= "Check whether there is double space or not"
# print(len(name)) # This will show the length of the variable
# print(name.endswith("brother.")) #This will show if the variable ends with "brother." or not, true or false
# print(name.count("a")) # Count the number of repetation of the string/character in the string
# print(name.capitalize()) #This function will remove the capital letters of the particular string
# print(name.upper()) #will capitalize all the words
# print(name.lower()) #will remove all the capital letters
# print(name.title())
# print(name.replace("Sudip","Subash"))
# print(name.find("Sudip"))
# print('Sudip' in name) # The output will be either true or false checking the resence of string 'Sudip'
# print(doubleSpace.find(" "))
# print("\n-----------Here is a break to see it clearly-------------\n")
# print(name.join(["First sentence is " ,"\nSecond sentence is ", "\nLast sentence is not available by default!!! "]))
#This above join operation will simply add first sentence with the string at the begining and at the end of the sentence
# print("\n4. Finding the gcd of any two integers")
# import math
# print(math.gcd(198,252))
# print("\n5. Displaying the functions in time module")
# import time
# print(dir(time))
# # this will provide the functions inside module of "time"
# print("\n6. This is how you can declare integers in python")
# a, b,c, d=40,30,20,10
# print(a+b+c)
# # output = 90
# z= (23,"Sudip", 23.5)
# print(z)
# # Arithmetic Operation
# print(10%3) #1
# print(10/3) #3.333333
# print(10//3) #3
# print(10*3) #30
# print(10**3) #1000
# print(10+3*2*2) # Operator precedence
# print(abs(-29)) #absolute value =29
# import math
# print(math.ceil(2.9)) #ceil value
# print("\n7. Displaying the datatype in python")
# a=90
# b=82.9898984342
# b=False
# print(type(a)) # output=<class 'int'>
# print(type(b)) # output=<class 'float'>
# print(type(c)) # output=<class 'bool'>
# print("\n8. Choosing the random number using python")
# from random import*
# when want just a space inbetween random numbers
# print(randint(0,10),randint(0,10))
# when you want particular/manual space inbetween random numbers
# print(randint(0,10), randint(0,10),randint(0,10),sep='')
# print("\n9. User input")
# name = input("Enter your name ")
# print(name)
# print("\n10. Send letter to multiple people")
# letter = '''Hello, <|NAME|>
# You have been selected in my python program.
# Happy to see you in the program.
# Greeeting from the company head.
# Date: <|DATE|>'''
# name=input("Enter name of the candidate: ")
# date=input("Enter date: ")
# letter=letter.replace("<|NAME|>",name)
# letter=letter.replace("<|DATE|>",date)
# print(letter)
# # print("\n11. Over write the list data")
# a= [2,3,4,5,6,7]
# a[1]=34
# print(a) ##here the ouput will replace 3 with 34
# print(a[2]) ## The output will be only 4
# print("\n12. Listing indexing")
# list=[20,30,40,50,"Sudip"]
# print(list[2])
# print(list[0:5])
# print(list.reverse())
# # List Methods
# # 1. list.reverse()
# # 2. list.sort
# # 3. list.oppend
# name=input("Enter yout name ")
# color=input("Enter your favourite color ")
# print(name + " likes " + color + " color")
# birth=input("Enter your birth year")
# print("\n13. Use integer calculation")
# current_year= input("Eneter current year")
# your_age= int(current_year)-int(birth)
# print(your_age)
# print("\n14. Ask a user weight in gram, convert to kilogream and print on the terminal")
# weight= input("Enter the weight in gram")
# kilogram= int(weight)/1000
# print(kilogram)
# # IF else condition and indentaton matters in python
# is_hot= False
# is_cold= False
# if is_hot:
# print("It's hot day")
# elif is_cold:
# print("It's not hot day")
# print("Please wear warm clothes")
# print("I am not happy right now")
# else:
# print("Its a lovely day")
# print("beautiful")
#if an applicant has high income and good credt eligible for loan
# high_incoome= True
# has_good_credit= True
# if high_incoome:
# if has_good_credit:
# print("Eligible for loan")
# else:
# print("SOrry, you don't have good credit due to which we are not abl to give loan")
# else:
# print("Not eligible for bank loan")
# print("\n Use of and operator")
# if_good_credit=True
# not_a_criminal= True
# if if_good_credit and not_a_criminal:
# print("Give loan")
# else:
# print("Kick his ass")
#Comparision operator in python
# temperature= int(input("Enter tem in degree celcius: "))
# if (temperature<30):
# if (temperature>15):
# print("It's bearutiful day")
# else:
# print("It's a cold day")
# else:
# print("It's a cold day")
# print("/n Project to convert kg to gram and vice versa")
# weight= int(input("Enter weight:"))
# unit= input("K or g")
# if unit.upper()==K:
# convert=weight*1000
# print(f"You are {convert} grams ")
# else:
# convert= g/1000
# print("You are {convert} kilos")
## while loop
# i=1
# while i<5:
# print('*'*i)
# i+=1
# print("Done")
##projec 2
# Guess a number to win
# secret_number= 9
# Guess_count=0
# Guess_limit=3
# while Guess_count < Guess_limit:
# Guess=int(input("Guess: "))
# Guess_count+=1
# if Guess==secret_number:
# print("You Won!")
# break
# else:
# print('Your failed!')
# #
# # for loop
# 1
# for a in 'python':
# print(a)
# 2.
# for item in range(1,12,2): # Z belongs to 1 to 12, where the number 2 is the number of step jump
# print(item)