Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Cicli
CICL I, RIPE T IZIO NI, INT E RVALLI, S E QUENZE
Chapter 4
False
C Corpo
True
B
Ripetizione
Uscita
D
Passi
Traccia il
ciclo
Calculare e
stampare la media
di salary usando le
variabili total e
count
# Priming read
salary = float(input("Enter a salary or -1 to finish: "))
while salary >= 0.0 :
total = total + salary
count = count + 1
# Modification read
salary = float(input("Enter a salary or -1 to finish: "))
done = False
Inizializzare done in modo che si entri nel ciclo
while not done :
value = float(input("Enter a salary or -1 to finish: "))
if value < 0.0:
done = True
else : Settare il ‘flag’ done a Vero se si trova la
# Process value sentinella
total = 0.0
inputStr = input("Enter value: ")
while inputStr != "" :
value = float(inputStr)
total = total + value
inputStr = input("Enter value: ")
if count > 0 :
average = total / count
else :
average = 0.0
valid = False
while not valid :
value = int(input("Please enter a positive value < 100: "))
if value > 0 and value < 100 :
valid = True
else :
print("Invalid input.")
i = 1
while i < 10 :
Versione while
print(i)
i = i + 1
T F
C2
B
B2
Vero
n= 1
Falso
n <= 4?
Vero
Print xn
x=x+1
▪ end=
o Definisce cosa stampare alla fine di riga
o Default: «a capo» '\n'
o print('Hello', end='')
if found :
print("First digit occurs at position", position)
else :
print("The string does not contain a digit.")
https://en.wikipedia.org/wiki/Playing_cards_in_Unicode
https://en.wikipedia.org/wiki/Playing_cards_in_Unicode