A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

what is the type of int*float?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    the answer will come out as a float even for like 4.5*2 the answer will come out 9.0 instead of just 9.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    this is called the type conversion and the precedence of float is greater than int thus answer must be in float

  3. carlsmith
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ints generally become floats whenever it'd be obvious for them to do so, floats never become ints unless you explicitly tell them to do so.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It is float because most of the compilers does automatic type conversion during the semantic analysis phase. So, in general all the types of the variable involved in an expression are converted into one single type (The highest type .. in your case, float) before the equation is evaluated...

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @carlsmith Your not completely wrong but that wouldn't be the best explanation because look at lets say 10/4 you would expect it to return 2.5 but it returns 2 so therefore it doesn't become a float when it needs to only when given a float. (kenators explanation is correct)

  6. carlsmith
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @Onyx - If you write the expression 10 / 4, you get 2 because this, at least in Python2, does floor division. It has nothing to do with intuitive type conversion. If you take the two ints, 10 and 4, and do sane division 10 // 4, you get 2.5, a float, as expected. In Python3, 10 / 4 returns a float and 10 // 4 returns an int. This is an issue with the counter-intuitive syntax of division operators before Python3, it's nothing to do with ints and floats.

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Most people that take this course use 2.x because thats what the teacher uses. And I said you weren't completely wrong that just wasn't the best way to explain for someone that doesn't understand type conversion unless you already knew he was using 3.xsyntax.

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.