-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython basic.py
More file actions
73 lines (59 loc) · 2.2 KB
/
python basic.py
File metadata and controls
73 lines (59 loc) · 2.2 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
#Write a Python program to get the Python version you are using.
import sys
print("Python version")
print (sys.version)
print("Version info.")
print (sys.version_info)
#Write a Python program to display the current date and time.
Sample Output :
Current date and time :
2014-07-05 14:34:14
import datetime
now = datetime.datetime.now()
print ("Current date and time : ")
print (now.strftime("%Y-%m-%d %H:%M:%S"))
#Write a Python program which accepts the radius of a circle from the user and compute the area.
Sample Output :
r = 1.1
Area = 3.8013271108436504
from math import pi
r = float(input ("Input the radius of the circle : "))
print ("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2))
#Write a Python program which accepts the user's first and last name and print them in reverse order with a space between them
fname = input("Input your First Name : ")
lname = input("Input your Last Name : ")
print ("Hello " + lname + " " + fname)
#Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers
Sample data : 3, 5, 7, 23
Output :
List : ['3', ' 5', ' 7', ' 23']
Tuple : ('3', ' 5', ' 7', ' 23')
values = input("Input some comma seprated numbers : ")
list = values.split(",")
tuple = tuple(list)
print('List : ',list)
print('Tuple : ',tuple)
Write a Python program to accept a filename from the user and print the extension of that.
Sample filename : abc.java
Output : java
filename = input("Input the Filename: ")
f_extns = filename.split(".")
print ("The extension of the file is : " + repr(f_extns[-1]))
Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn.
Sample value of n is 5
Expected Result : 615
a = int(input("Input an integer : "))
n1 = int( "%s" % a )
n2 = int( "%s%s" % (a,a) )
n3 = int( "%s%s%s" % (a,a,a) )
print (n1+n2+n3)
10. Write a Python program to convert seconds to day, hour, minutes and seconds.
time = float(input("Input time in seconds: "))
day = time // (24 * 3600)
time = time % (24 * 3600)
hour = time // 3600
time %= 3600
minutes = time // 60
time %= 60
seconds = time
print("d:h:m:s-> %d days :%d hours:%d minutes:%d seconds" % (day, hour, minutes, seconds))