-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelloworld.py
126 lines (87 loc) · 2.02 KB
/
helloworld.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
118
119
120
121
122
123
124
125
126
#Python Tutorial taken from https://www.w3schools.com/python
msg = 'Hello World'
print (msg)
#test comment
x = 5
y = 'John'
print(x,y)
x = 'Python is '
y = 'awesome'
z = x + y
print(z)
#global variables
a = 'awesome!'
def myfunc():
print('Python is', a)
myfunc()
#local variables can have the same name is global variables (and not affect the global variable)
#variables created outside functions are global, those created inside functions are local variable
def mylocalfunc():
a = 'fantastic!!'
print(x,a)
mylocalfunc()
print(x,a)
#variables created inside the function can be made global by the global function
def myglobalfunc():
global a
a = 'globally awesome!'
myglobalfunc()
print(x,a)
#getting the data type
print (type(x))
#Python will auto detec type of variables and numbers
x = 1 # int
y = 2.8 # float
z = 1j # complex
print(type(x))
print(type(y))
print(type(z))
#Conveting numbers to other types, although complex numbers can't be converted
x = 1 # int
y = 2.8 # float
z = 1j # complex
#convert from int to float:
a = float(x)
#convert from float to int:
b = int(y)
#convert from int to complex:
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
#No inbuilt random function but there is a module
import random
print(random.randrange(1,10))
#Although Python auto detects variables you can force select
x = int(1) # x will be 1
y = int(2.8) # y will be 2
z = int("3") # z will be 3
print(x)
print(y)
print(z)
x = float(1) # x will be 1.0
y = float(2.8) # y will be 2.8
z = float("3") # z will be 3.0
w = float("4.2") # w will be 4.2
print(x)
print(y)
print(z)
print(w)
x = str("s1") # x will be 's1'
y = str(2) # y will be '2'
z = str(3.0) # z will be '3.0'
print(x)
print(y)
print(z)
#Multiline strings
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
#test commit form 2nd laptop
#test commit from desktop and setup of git
##further test