Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python Request for help with type conversion

# Definition of savings and result
savings = 100
result = 100 * 1.10 ** 7

# Fix the printout
print("I started with $" + savings + " and now have $" + result + ". Awesome!")

# Definition of pi_string
pi_string = "3.1415926"

# Convert pi_string into float: pi_float
 
# Definition of savings and result
savings = 100
result = 100 * 1.10 ** 7

# Fix the printout
print("I started with $" + savings + " and now have $" + result + ". Awesome!")

# Definition of pi_string
pi_string = "3.1415926"

# Convert pi_string into float: pi_float
Python:
# Definition of savings and result
savings = 100
result = 100 * 1.10 ** 7

# Fix the printout
print("I started with $" + savings + " and now have $" + result + ". Awesome!")

# Definition of pi_string
pi_string = "3.1415926"

# Convert pi_string into float: pi_float
pi_float = float(pi_string)

Specifically, I am having great confusion with calling the string function. If anyone has suggestions, I will be most grateful.
To call ths `string` function, you just wrap the variable you want to convert into a string in `str()` e.g `str(number)`.
 
Python:
# Definition of savings and result
savings = 100
result = 100 * 1.10 ** 7

# Fix the printout
print("I started with $" + savings + " and now have $" + result + ". Awesome!")

# Definition of pi_string
pi_string = "3.1415926"

# Convert pi_string into float: pi_float
pi_float = float(pi_string)


To call ths `string` function, you just wrap the variable you want to convert into a string in `str()` e.g `str(number)`.
Many thanks. I tried and failed to implement your suggestion. Please find attached a snapshot of the shell. What am I doing wrong?
 

Attachments

  • Screenshot_20220602-044324.jpg
    Screenshot_20220602-044324.jpg
    471.4 KB · Views: 4
Many thanks for your ongoing generosity and patience. There was a directive to call savings. I did so and called result, too, since their syntax seems equivalent to my naive eyes. What am I failing to grasp? Again, many thanks for your ongoing generosity and patience.
I see the shell displays no error at bottom. Are they being inconsistent?
 

Attachments

  • Screenshot_20220602-053539.jpg
    Screenshot_20220602-053539.jpg
    736.4 KB · Views: 4
Hey,

So that error is correct 🙂 what you should be doing is :-

Python:
Savings = str(100)

#or

Savings = "100"

#or

print(str(Savings))

putting " " around something turns that into a string where as 100 would be a int. You also cannot turn a variable into a string or a int but you can convert what ever you are putting inside the variable into a str or int.

Hope this makes sense 😀
 
Hello, simong1993 --

Please find the two attachments which demonstrate whatever it is I did wrong this time. If you have time to disabuse me of my ignorance and misunderstandings, I will of course be most grateful.

Many thanks,

Coding Novice
 

Attachments

  • Screenshot_20220602-171403.jpg
    Screenshot_20220602-171403.jpg
    372.3 KB · Views: 1
  • Screenshot_20220602-171124.jpg
    Screenshot_20220602-171124.jpg
    728.2 KB · Views: 1
This one may be partly my fault lol. With python she is very picky lol Savings and savings are two diffrent varibles. In your instance you are doing this:-
Python:
Savings = "100"
print(str(savings))

#You need to do this

savings = "100"
print(str(savings))

#Lose the caps :D
 
This one may be partly my fault lol. With python she is very picky lol Savings and savings are two diffrent varibles. In your instance you are doing this:-
Python:
Savings = "100"
print(str(savings))

#You need to do this

savings = "100"
print(str(savings))

#Lose the caps :D
Again, many thanks. Python is still being picky; please see the attachment. I look forward to being enlightened again.
 

Attachments

  • Screenshot_20220602-191424.jpg
    Screenshot_20220602-191424.jpg
    421.7 KB · Views: 2
Thats not a python issue, restart the code so its back to how you started then make the changes. you must have changed something it didnt want you too 🙂
Again, many thanks. I do not think I can restart the exercise, at least so far as I can see. That said, I deleted a hash before print and ended up with another line in the shell. This one reads: "I started with $100 and now have $100 * 1.10 ** 7. Awesome!". I will email the website and ask about restarting the code. 🙂
 
Again, many thanks. I do not think I can restart the exercise, at least so far as I can see. That said, I deleted a hash before print and ended up with another line in the shell. This one reads: "I started with $100 and now have $100 * 1.10 ** 7. Awesome!". I will email the website and ask about restarting the code. 🙂
Sorry! I thought wrong and have reset the code. I will try and see what happens.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom