fork download
  1. def txt_to_json(calories, proteins, fats, carbohydrates):
  2. # Format the string manually
  3. result = "{" + f'"Calories":{calories}, "Proteins": {proteins}, "Fats": {fats}, "Carbohydrates":{carbohydrates}' + "}"
  4.  
  5. return result
  6.  
  7. # Example usage:
  8. calories = 100
  9. proteins = 30
  10. fats = 40
  11. carbohydrates = 30
  12.  
  13. print(txt_to_json(calories, proteins, fats, carbohydrates))
  14.  
Success #stdin #stdout 0.04s 9580KB
stdin
100
30
40
30
stdout
{"Calories":100, "Proteins": 30, "Fats": 40, "Carbohydrates":30}