-
Notifications
You must be signed in to change notification settings - Fork 0
/
in_out.py
76 lines (65 loc) · 2.05 KB
/
in_out.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
# -*- coding: utf-8 -*-
'''
Ejemplos de Entrada / Salida
'''
from math import pi
def circle_length(radius):
return 2*pi*radius
def half(valor):
return valor/2
def main():
'''
Lectura de datos desde el teclado: raw_input
Debemos especificar qué tipo de datos queremos leer
'''
#Leemos el radio desde el teclado
rad = float(raw_input())
print circle_length(rad)
#mejor: mensaje introductorio
rad = float(raw_input("radio = "))
print circle_length(rad)
def main2():
#Cuidado con qué quieres leer
x = raw_input("dato = ")
y = int(raw_input("dato = "))
z = float(raw_input("dato = "))
#print mitad(x), mitad(y), mitad(z)
print half(y), half(z)
def main3():
#mejorando print
r = float(raw_input("radius = "))
print "The circle length is", circle_length(r)
#puede mostrar distintos mensajes separados por comas
#otra forma
print "The circle length is",
print circle_length(r)
def main4():
#SALIDA CON FORMATO
n = int(raw_input("n = "))
#presentamos por pantalla sin ningún tipo de formato
for k in range(2, 11):
print n, "elevado a", k, "es igual a", n**k
print '='*10
#presentamos por pantalla utilizando un formato de salida
for k in range(2, 11):
print '%d elevado a %d es igual a %d' % (n, k, n**k)
print '='*10
'''
%<numero>d --> formato enteros
%<numero1.numero2>f --> formato flotantes
%s --> cadenas
'''
#Con un buen formato, mejoramos la presentación
for k in range(2, 11):
print '%d elevado a %2d es igual a %9d' % (n, k, n**k)
print '='*10
#Podemos mezclar reales y enteros
for k in range(1, 10):
print 'la circunferencia de radio %d tiene longitud %f' % (k, circle_length(k))
print '='*10
for k in range(1, 10):
print 'la circunferencia de radio %d tiene longitud %5.1f' % (k, circle_length(k))
print '='*10
for k in range(1, 10):
r = 1.0/k
print 'la circunferencia de radio %4.2f tiene longitud %5.1f' % (r, circle_length(r))