You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Python/Basic Exercises I.py
+30-61Lines changed: 30 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -34,13 +34,13 @@
34
34
# Area = 3.8013271108436504
35
35
frommathimportpi
36
36
r=float(input("Input the radius of the circle : "))
37
-
print("The area of the circle with radius "+str(r) +" is: "+str(pi*r**2))
37
+
print(f"The area of the circle with radius {r}is: {str(pi*r**2)}")
38
38
39
39
40
40
# 5. Write a Python program which accepts the user's first and last name and print them in reverse order with a space between them.
41
41
fname=input("Input your First Name : ")
42
42
lname=input("Input your Last Name : ")
43
-
print("Hello "+lname+" "+fname)
43
+
print(f"Hello {lname}{fname}")
44
44
45
45
46
46
# 6. Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers.
@@ -50,20 +50,20 @@
50
50
# Tuple : ('3', ' 5', ' 7', ' 23')
51
51
52
52
color_list= ["Red", "Green", "White", "Black"]
53
-
print("%s %s"% (color_list[0], color_list[-1]))
53
+
print(f"{color_list[0]}{color_list[-1]}")
54
54
55
55
# 7. Write a Python program to accept a filename from the user and print the extension of that.
56
56
# Sample filename : abc.java
57
57
# Output : java
58
58
filename=input("Input the Filename: ")
59
59
f_extns=filename.split(".")
60
-
print("The extension of the file is : "+repr(f_extns[-1]))
60
+
print(f"The extension of the file is : {repr(f_extns[-1])}")
61
61
62
62
63
63
# 8. Write a Python program to display the first and last colors from the following list.
64
64
# color_list = ["Red","Green","White" ,"Black"]
65
65
color_list= ["Red", "Green", "White", "Black"]
66
-
print("%s %s"% (color_list[0], color_list[-1]))
66
+
print(f"{color_list[0]}{color_list[-1]}")
67
67
68
68
69
69
# 9. Write a Python program to display the examination schedule. (extract the date from exam_st_date).
@@ -78,9 +78,9 @@
78
78
# Expected Result : 615
79
79
80
80
a=int(input("Input an integer : "))
81
-
n1=int("%s"%a)
82
-
n2=int("%s%s"% (a, a))
83
-
n3=int("%s%s%s"% (a, a, a))
81
+
n1=int(f"{a}")
82
+
n2=int(f"{a}{a}")
83
+
n3=int(f"{a}{a}{a}")
84
84
print(n1+n2+n3)
85
85
86
86
# 11. Write a Python program to print the documents (syntax, description etc.) of Python built-in function(s).
@@ -132,10 +132,7 @@
132
132
133
133
134
134
defdifference(n):
135
-
ifn<=17:
136
-
return17-n
137
-
else:
138
-
return (n-17) *2
135
+
return17-nifn<=17else (n-17) *2
139
136
140
137
141
138
print(difference(22))
@@ -168,9 +165,7 @@ def sum_thrice(x, y, z):
168
165
169
166
# 19. Write a Python program to get a new string from a given string where "Is" has been added to the front. If the given string already begins with "Is" then return the string unchanged.
# 50. Write a Python program to print without newline or space.
486
-
foriinrange(0, 10):
455
+
for_inrange(10):
487
456
print('*', end="")
488
457
print("\n")
489
-
458
+
490
459
491
460
# 51. Write a Python program to determine profiling of Python programs.
492
461
# Note: A profile is a set of statistics that describes how often and for how long various parts of the program executed. These statistics can be formatted into reports via the pstats module.
0 commit comments