Python Forum
How to get number with print statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get number with print statement
#1
I wrote program to add two integer.
(using python 2.7)
print "Promote user to enter first number"

number1 = int(raw_input())

print "Promote user to enter second number"

number2 = int(raw_input())

addition = number1 + number2

print "addition : ", addition
I get the following output

Promote user to enter first number
2
Promote user to enter second number
5
addition : 7

But I want following output

Promote user to enter first Number : 2

Promote user to enter second Number : 5

addition : 7

How to get the accepted output
Reply
#2
don't use print to display the prompt, but raw_input
number1 = int(raw_input("Promote user to enter first number"))
number2 = int(raw_input("Promote user to enter second number"))
addition = number1 + number2
print "addition : {}".format(addition)
That said, why do you use python2? As newbie, you should start with python3. python2 official support ends in less than 1.5 years
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Print Player Name and Number of Pokemon webmanoffesto 1 1,109 Aug-23-2022, 08:54 PM
Last Post: deanhystad
  Why doesn't this print statement work? stylingpat 10 5,744 Mar-23-2021, 07:54 PM
Last Post: buran
  print two different sequence number mantonegro 2 1,666 Nov-16-2020, 06:19 PM
Last Post: mantonegro
  Runs perfect in Python but fails to print last statement when converted to .exe. Help sunil422 3 2,828 Aug-13-2020, 01:22 PM
Last Post: deanhystad
  Print the number of items in a list on ubuntu terminal buttercup 2 1,947 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,745 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Taking brackets out of list in print statement pythonprogrammer 3 2,401 Apr-13-2020, 12:25 PM
Last Post: perfringo
  capture print statement written in Stored Procedure in SQL Server brijeshkumar_77 0 2,559 Feb-18-2020, 03:22 AM
Last Post: brijeshkumar_77
  printing a list contents without brackets in a print statement paracelx 1 2,129 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  Print 'X' a number of times Than999 1 2,648 Jan-18-2020, 06:41 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020