-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprograms.py
More file actions
103 lines (78 loc) · 2.5 KB
/
Copy pathprograms.py
File metadata and controls
103 lines (78 loc) · 2.5 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
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
import sys
from datetime import datetime
# 1. Print Welcome
print("Welcome")
# 2. Print the given word
word = "Python"
print(word)
# 3. Print the given message
message = "Have a nice day"
print(message)
# 4. Print the given integer number
num = 25
print(num)
# 5. Print the given fractional number
frac = 3.14159
print(frac)
# 6. Print the given fractional number in 2-digit decimal format
print(f"{frac:.2f}")
# 7. Print the given integer number in hexadecimal format
print(hex(num)) # with 0x prefix
print(f"{num:x}") # without prefix
# 8. Print the given integer number in octal format
print(oct(num)) # with 0o prefix
print(f"{num:o}") # without prefix
# 9. Print the given hexadecimal number in integer format
hex_str = "0x19"
print(int(hex_str, 16))
# 10. Print the given octal number in integer format
oct_str = "0o31"
print(int(oct_str, 8))
# 11. Print the ASCII value of a character
ch = 'A'
print(ord(ch))
# 12. Print the character for the given ASCII value
ascii_val = 65
print(chr(ascii_val))
# 13. Print two numbers with a space between them
a, b = 10, 20
print(a, b)
# 14. Print two numbers with a tab space between them
print(f"{a}\t{b}")
# 15. Print two numbers in two lines
print(a)
print(b)
# 16. Print a character in single quotes
print(f"'{ch}'")
# 17. Print two words in double quotes
print('"Hello World"')
# 18. Print your date of birth in the format DD/MM/YYYY
dob = "15/08/2004" # replace with your actual DOB
print(dob)
# 19. Print an integer with a plus sign (+) before it
positive_num = 42
print(f"{positive_num:+d}")
# 20. Print the size of char, int, float, and double
# Python has no fixed char/int/double types like C, so sizes are shown
# via sys.getsizeof() for Python's own object representation.
print("char (1 char str):", sys.getsizeof('a'), "bytes")
print("int:", sys.getsizeof(1), "bytes")
print("float:", sys.getsizeof(1.0), "bytes")
print("double (same as float in Python):", sys.getsizeof(1.0), "bytes")
# 21. Print your roll number and name
roll_no = 123
name = "John"
print(f"Roll No: {roll_no}, Name: {name}")
# 22. Print your marks in 5 subjects each on a new line
marks = [85, 90, 78, 92, 88]
for m in marks:
print(m)
# 23. Print your blood group
blood_group = "O+" # replace with your actual blood group
print(blood_group)
# 24. Print current time in the format HH:MM:SS
now = datetime.now()
print(now.strftime("%H:%M:%S"))
# 25. Print your address in multiple lines using \n
address = "123 Main Street\nNamakkal\nTamil Nadu\nIndia"
print(address)