+ 3

Argentina

I’m using python to solve a problem. You are in a hat store in Argentina! The prices are listed in US Dollars and Argentinian Pesos. You have both, but you want to make sure you pay the lower price! Do you pay in Dollars or Pesos? The exchange rate is 2 cents for every Peso. Task Create a program that takes two prices and tells you which one is lower after conversion. Here is my code: x=int(input()) y=int(input()) z=x*0.02 if z>y: print(“Dollars”) else: print(“Pesos”) Is there a more simple way to write this code?

2nd Jan 2021, 6:05 AM
Haha36
6 Answers
+ 6
p = int(input()) d = int(input()) e = d * 50 if e < p: print("Dollars") else: print("Pesos")
2nd Jan 2021, 9:00 AM
Nilla
+ 5
Haha36 Idk why you want it to be shortened further .It is already a very short program ...lol This is just 1 stmt shorter : x =int(input()) y =int(input()) if (x/50)>y: print("Dollars") else: print("Pesos")
2nd Jan 2021, 6:20 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 3
Haha36 Your code is nice and simple which makes it easy to read and understand. There are many ways of writing code to achieve an objective. I would like to share 2 examples with you. Example 1 Assign a lambda function to a variable and place it in a list comprehension using a boolean value to generate the result: convert = (lambda pesos,dollars: pesos*0.02-dollars) (int(input()),int(input())) print("Dollars" if convert >0 else "Pesos") Example 2 A one-liner which is always fun, but rarely readable: print(*["Dollars" if (int(input()) * 0.02 - int(input())) >0 else "Pesos"])
2nd Jan 2021, 9:06 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
ar = int(input()) us = int(50*int(input())) if us < ar: print("Dollars") else: print("Pesos") i made this and worked
5th Feb 2022, 3:13 PM
Ferhat FIRAT
Ferhat FIRAT - avatar
0
P = int(input()) D = int(input()) res = P/D if res >= 50: print("Dollars") elif res < 50: print ("Pesos")
8th Jul 2022, 10:19 AM
Eugene Nester
Eugene Nester - avatar
0
peso_to_dollar = (float(input())/4000)*80 new_dollar = ((float(input())) - 0.02) if new_dollar < peso_to_dollar: print('Dollars') else: print('Pesos')
31st Oct 2022, 7:34 PM
Hamish Zwain