A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
what is the type of int*float?
anonymous
 5 years ago
what is the type of int*float?

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0the answer will come out as a float even for like 4.5*2 the answer will come out 9.0 instead of just 9.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0this is called the type conversion and the precedence of float is greater than int thus answer must be in float

carlsmith
 5 years ago
Best ResponseYou've already chosen the best response.0ints 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0It 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...

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.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)

carlsmith
 5 years ago
Best ResponseYou've already chosen the best response.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 counterintuitive syntax of division operators before Python3, it's nothing to do with ints and floats.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Most 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.
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.