-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirstprogram.py
117 lines (94 loc) · 2.14 KB
/
Firstprogram.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
print("My name is Mushrafali.", "I am 23 years old.")
print("This is my first program in python.")
print(23)
print(12+89)
# variables
name = "mushrafali"
age = 23
price = 99.9
print(price)
print(age)
print("My name is", name)
age2 = age
print(age2)
# datatypes
print(type(name)) #String
print(type(age)) #Integer
print(type(price)) #Float
a = False
b = None
print(type(a)) #Boolean
print(type(b)) #None
# arithmetic operators
a = 1000
b = 54
sum = a + b
diff = a - b
print(sum)
print(diff)
print(a / b)
print(a * b)
print(a % b) #reminder
print(a ** b) #a^b
# relational / comparison operators
print(a == b) #False
print(a != b) #True
print(a >= b) #True
print(a > b) #True
print(a <= b) #False
print(a < b) #False
# assignment operators
num = 20
num += 10 #num = num + 10 = 30
num -= 10 #num = num - 10 = 20
print("num :", num)
num *= 10 #200
print("num :", num)
num /= 10 #20
print("num :", num)
num **= 10 #20
print("num :", num)
num %= 10
print(num) #0
# logical operators
a = 50
b = 30
print(not False) #True
print(not (a>b)) #False
val1 = True
val2 = False
val3 = True
print("AND operator :", val1 and val2) #False bc both are diff values
print("OR operator :", val1 or val2) #True bc one of them is true
print("OR operator :", (a == b) or ( a > b )) #True
# type conversion
a = 2
b = 4.23
print(a + b) #2.0 + 4.23 => 6.23
# type casting
a = int("2") #"2" is a string which cannot be added with float or int so we have to change its type first
b = 4.2
print(type(a))
print(a + b) #6.23
a = 3.14
a = str(a)
print(type(a))
#input
name = input("Enter your name :")
print("WELCOME ", name)
val = input("enter some value :")
print(type(val), val) # "20" "name" "2.33" the type will be string
val = int(input("enter some value :"))
print(type(val), val) # value will be an integer
#for example
name = input("enter your name :")
age = int(input("entre your age :"))
marks = float(input("enter your marks :"))
print("WELCOME", name)
print("age =", age)
print("marks =", marks)
# single line comments
"""
multiple
line comments
"""