-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path011_While.py
58 lines (35 loc) · 973 Bytes
/
011_While.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
# WHILE
# Imprime edad cuando el contador llegue a 18
edad = 0
while edad < 18:
edad=edad+1
print("Tienes "+str(edad))
# Pregunta la edad mientras sea negativa
edad=int(input("Introduce edad: "))
while edad<0:
print("Edad incorrecta")
edad=int(input("Introduce edad: "))
print("tu edad es: "+str(edad))
# Calcula la raiz cuadrada de un número. Tenemos tres intentos y el número no puede ser negativo.
import math;
intentos=0;
num = int(input("Introduce numero: "))
while num<0:
intentos=intentos+1
print("Incorrecto")
num=int(input("Introduce numero: "))
if intentos==2:
print("Demasiados intentos")
break;
if intentos<2:
intentos=intentos+1
solucion=math.sqrt(num)
print("la raiz cuadrada de "+str(num)+ " es: "+str(solucion))
# Bucle while con un if anidado y un break
# Salga del bucle cuando num sea 3:
num = 1
while num < 6:
print(num)
if num == 3:
break
num += 1