Skip to content
Programs · Program 5-5

Q.Program 5-5: Program of explicit type conversion from int to float.

Puducherry TnboardTextbookSubjective· 2mImportance★★★★★est
20% · 10/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Calling float() on an integer is explicit type conversion — the programmer forces the change, and 87 becomes 87.0.

The idea (Explicit Type Conversion). In explicit conversion (also called type casting) the programmer deliberately converts a value from one type to another using a constructor function such as float(), int() or str(). This is different from implicit conversion, where Python changes the type on its own during mixed-type arithmetic. Converting int → float is always safe: no information is lost, the value just gains a fractional part .0.

Program

# prog5-5.py
# Program of explicit type conversion from int to float
marks1 = 45
marks2 = 42
total = marks1 + marks2        # int + int -> int
totalFloat = float(total)      # explicit int -> float
print(total)
print(totalFloat)
print(type(totalFloat))

Expected output

87
87.0
<class 'float'>

Key lines

  • total = marks1 + marks2 — both operands are int, so the result 87 is an int; Python does not convert anything here. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.