-1

basically, what the title says, I would like to add that specific number to a list of different numbers. I'm new to programming and I'm not sure where to start. Any help would be very much appreciated. Thank you.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Stack Overflow is neither a discussion forum nor a tutorial, code-writing, or homework service. This is a Q&A site where *specific* programming questions (usually, but not always, including some code) get *specific* answers. Please take the [tour] and carefully read through the [help] to learn more about the site, including [ask], as well as [what is on-topic](https://stackoverflow.com/help/on-topic) and [what is not](https://stackoverflow.com/help/dont-ask). Please also follow the [question checklist](https://meta.stackoverflow.com/q/260648). – MattDMo Oct 04 '22 at 20:50

1 Answers1

1

The easiest way is to use a list comprehension like this:

your_numbers = [9.5, 9.1, 8.3]
output = [number + 29.83 for number in your_numbers]

Please note that float has limited precision, so the output is:

[39.33, 38.93, 38.129999999999995]

You can add round() to get the output you expect:

output = [round(number + 29.83, 2) for number in your_numbers]

[39.33, 38.93, 38.13]
bitflip
  • 3,436
  • 1
  • 3
  • 22