this post was submitted on 04 Sep 2024
7 points (100.0% liked)

Python

6220 readers
15 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

I'm currently doing Dr. Charles Severence's lessons on FreeCodeCamp to try to learn Python3. I'm on lesson exercise 02_03 and confused about multiplying floating-point and integer values.

The goal is to write a Python program multiplying hours worked by pay rate to come up with a pay quantity.

This is the code I wrote:

h = input("Enter hours: ")
r = input("Enter pay rate: ")
p = float(h) * r

I got a traceback error, and the video said the correct way to solve said error was change Line 3 from p = float(h) * r to p = float(h) * float(r).

However, what I'm confused about is why would I need to change r to a floating-point value when it's already a floating-point value (since it'd be a currency value like 5.00 or something once I typed it in per the input() command*?

What am I missing here?

Β 


*I can't remember: are the individual commands in a python line called "commands"?

Β 

Β 


Edit: Wrote plus signs in my post here instead of asterisks. Fixed.

Β 


EDIT: Thanks to @[email protected] and @[email protected]. I thought that the input() function was a string until the end-user types something in upon being prompted, and then becomes a floating-point value or integer value (or stays a string) according to what was typed.

This is incorrect: the value is a string regardless of what is typed unless it is then converted to another type.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 5 points 1 week ago (5 children)

That's fair, I was trying to be a bit vague since you're learning and wanted to help point you to the solution. Went a little too vague with it πŸ™‚

[–] [email protected] 2 points 1 week ago (4 children)

I really appreciate the effort! My dream is to eventually learn enough from free online courses to then take a certification test and then maybe I can get a job even though I don't have a degree. I fear my lack of a degree will doom that goal before I ever get a chance, but I have to take that chance, I feel. Also, I fucking hate customer service. Lol.

[–] [email protected] 2 points 1 week ago (1 children)

Eh, degrees can be overrated. I don't have one and it hasn't hindered me at all. Ultimately, it depends what kind of work you want to get into and your drive to self learn, how quick you can pick things up, and adaptability. You got this.

[–] [email protected] 2 points 1 week ago* (last edited 1 week ago)

I don't mind self-learning. Hell, if I'm interested in the subject matter, I usually find myself experimenting and researching.

I'm all about that "wait, I wonder if..." mindset. 😎

load more comments (2 replies)
load more comments (2 replies)