Exercicio sobre moedas
This commit is contained in:
		
							
								
								
									
										22
									
								
								exercicios-python/moedas.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								exercicios-python/moedas.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
troco = 187
 | 
			
		||||
moedas = [1,5,10,25,50,100]
 | 
			
		||||
moedasr = moedas[::-1]
 | 
			
		||||
valor = 0 
 | 
			
		||||
moedas_final = 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
for moeda in moedasr:
 | 
			
		||||
    while valor < troco:
 | 
			
		||||
        valor += moeda
 | 
			
		||||
        moedas_final += 1 
 | 
			
		||||
        if valor > troco:
 | 
			
		||||
            moedas_final -= 1
 | 
			
		||||
            valor -= moeda
 | 
			
		||||
            break
 | 
			
		||||
        if valor == troco:
 | 
			
		||||
            print(moedas_final)
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
		Reference in New Issue
	
	Block a user