Advertisement
icarussiano

Untitled

Jan 15th, 2024
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. numeri = list(map(int, input("Scrivi i numeri separati da spazio: ").split()))
  2. somma = sum(n if i % 2 == 0 else -n for i, n in enumerate(numeri))
  3. somma_str = ''.join(f" {'+-'[i%2]} {n}" for i, n in enumerate(numeri))
  4. print(f"{somma_str[3:]} = {somma}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement