-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercicios_python_basico.py
More file actions
60 lines (47 loc) · 2.03 KB
/
exercicios_python_basico.py
File metadata and controls
60 lines (47 loc) · 2.03 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
# -*- coding: utf-8 -*-
"""Exercícios Python.ipynb
Automatically generated by Colab.
# Exercícios: números
"""
x = int(input("Informe X: ")) # Função int() é usada para converter de str para int pois input() sempre retorna uma str
y = int(input("Informe y: "))
if x - y == 0:
print("Ocorreu divisão por zero")
else:
z = (x ** 2 + y ** 2) / (x - y) ** 2
print ("Valor de Z: {}".format(z)) # Função format() é usada para trocar o placeholder {} na string pela variável numérica passada como argumento
acumulador = 0
for n in range(3, 333, 3):
acumulador += n
print ("A soma é: {}".format(acumulador))
"""# Exercícios: estrutura de repetição"""
salario = int(input("Informe o salário do funcionário: R$"))
if salario < 0:
print ("O salário informado não é válido")
else:
novo_salario = salario * 1.35
print("O novo salário é R${}".format(novo_salario))
notas = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # Cria uma lista com dez notas 0, já que estes valores serão sobrescritos depois
indice = 0
while indice < len(notas):
notas[indice] = int(input("Informe a nota {}: ".format(indice + 1)))
indice += 1 # Como Pyhton não possui loops for com autoincremento, é necessário incrementar o índice no fim do loop
acumulador = 0
for n in notas:
acumulador += n
acumulador /= 10
print("A média é: {}".format(acumulador))
numero_escolhido = int(input("Informe um número de 1 a 10: "))
if numero_escolhido < 1 or numero_escolhido > 10:
print("O número informado não é válido")
else:
for n in range(1, 11):
print("{} x {} = {}".format(numero_escolhido, n, numero_escolhido * n))
"""# Exercícios: strings"""
string = "Um elefante incomoda muita gente"
# Conforme demonstrado abaixo, a porção "elefante incomoda" corresponde à faixa de índices 3 a 20 (não incluso) da string
print(string[3:20])
string = input("Informe uma string: ")
string = string.replace(" ", "") # Retira os espaços em branco
string = string.upper() # Deixa a string em uppercase
print ("String modificada: " + string)