-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-tests.py
More file actions
164 lines (126 loc) · 4.16 KB
/
basic-tests.py
File metadata and controls
164 lines (126 loc) · 4.16 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#PYTHON BASICS
#Variables
age=20
price = 19.95
first_name = 'Mosh'
is_online = True #case sensitive, letra maiuscula é necessário
state = 'new pacient'
print("Hello World") #posso usar tanto uma '' quanto ""
print("\n")
print(age)
print(price)
print(first_name)
if is_online == True:
print(state)
#Input - Get the value input on the terminal and save it
name = input("\nWhat is your name? ")
print("Hello " + name) #concatenation
#Type conversion
birth_year = input("\n\nEnter your birth year: ")
age = 2022 - int(birth_year) #conversion is necessary, cuz the function returns a string value
print(age)
first = input("First: ")
second = input("Second: ")
sum = float(first) + float(second)
print("Sum: "+ str(sum)) #converte de float para str para ser possível concateanr
#String
course = 'Python for Beginners' #a object
print(course.upper()) #a method for let the string in upper case
print(course)
print(course.find('y')) #busca um dado na string e retorna o indice de onde se encontra (no caso 1)
print(course.replace('for', '4')) #substitui uma sentença por outra
print('Python' in course) #print if the sentence was found in the object str
#Arithmetic Operators
print(10+3) #addition
print(10-3) #subtraction
print(10*3) #multiplication
print(10/3) #division with many numbers after the dot
print(10//3) #division without numbers after the dot (return a integer)
print(10 % 3) #returns the remaint of the division
print(10 ** 3) #returns the result of the power
x=10
x += 3 # value x +3, or another operators
print(x)
#Operator Precedence
x = 10 + 3 * 2
print(x) # 16
x = (10 + 3) * 2
print(x) # 26
# Comparison Operators
x = 3>2 #boolean expression, returns a boolean value
print(x)
x = 3==2
print(x)
x = 3!=2
print(x)
#Logical Operators
price = 25
print(price > 10 and price < 30) #and == && operator
print(price > 10 or price < 30) #or == || operator
print(not price < 30) #not == !! operator inversus of any value that u have given
#if statements
temperature = 25
if temperature > 30: #indented represents the lines is in the block of code
print("It's a hot day")
print("Drink plenty of water")
elif temperature > 20:
print("It's a nice day")
elif temperature > 10:
print("It's a bit cold")
else:
print("It's cold")
print("\nDone")
#While loops
i = 1
while i <= 5:
print(i * '*') #multiplica a quantidade de asteriscos por i a cada iteration
i += 1
#Lists
names = ["John", "Bob", "Mosh", "Sam", "Mary"] #similiar a vetores
print(names)
print(names[0]) #to gete a especific name insert the index of the element
print(names[-1]) # print the last element of the list
print(names[-2]) # second element of the end of the list
names[0] = "Jon"
print(names)
print(names[0:3]) #print the start index to the end index, the elements in a range
#List Methods
numbers = [1,2,3,4,5]
numbers.append(6) #add in the final
numbers.insert(0,-1) #insert in the init
numbers.remove(3) #remove a element
numbers.clear() #clear the list
print(numbers)
print(1 in numbers)
print(10 in numbers)
print(len(numbers)) #show the lenght of the list
# For loops
numbers = [1,2,3,4,5]
for item in numbers: #printa os itens presentes na lista até o ultimo item
print(item)
#The range function
numbers = range(5) # a sequence of numbers
numbers = range(5,10) # a sequence of numbers that start at five and end at 10
numbers = range(5,10, 2) # a sequence of numbers that start at five and end at 10, but stops at the index two
print (numbers)
for number in numbers:
print(number)
#Tuples
numbers = (1,2,3,3) #parenteses is a tuple
#uples are unchangeble, imutable
numbers.count(3) #returns the quantity of elements 3 exists in the tuple
numbers.index(2) #returns the index of a first occurrence of a element
#Functions
def hello_func(greeting, name='You'):
# print("Hello")
return '{}, {}.'.format(greeting, name) #adiciona o elemento presente no argumento a frase
#hello_func()
#print(hello_func().upper())
print(hello_func('Hi'))
print(hello_func('Hi', name = 'Corey'))
def student_info(*args, **kwargs): #args representa um conjunto de argumentos e kwargs outro conjunto
print(args)
print(kwargs)
courses = ['Math', 'Art']
info = {'name': 'John', 'age': 22}
student_info(*courses, **info)