[Tutor] How to get two user inputs in same prompt seperated by a special character?

mariocatch mariocatch at gmail.com
Sat Jul 14 06:02:04 CEST 2012


On Fri, Jul 13, 2012 at 11:46 PM, Santosh Kumar <sntshkmr60 at gmail.com>wrote:

> Like in my script:
>
> #!/usr/bin/env python
> #-*- coding:utf-8 -*-
>
> print "You will be prompted to enter your height in feet and inches."
> height_in_feet = input("How much feet are you long: ")
> remaining_inches = input("How much inches remained? ")
>
> inches_in_feet = height_in_feet * 12
>
> total_height_in_inches = inches_in_feet + remaining_inches
>
> print "You are %d inches long." % total_height_in_inches
>
>
> Here I want something like:
> Enter you height in format like 5' 10"
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Here's one way:

FEET_SEPERATOR = "'"
height = raw_input("Enter your height (ie: 6'1)")
heightSplit = height.split(FEET_SEPERATOR)
heightFeet = int(heightSplit[0])
heightInches = int(heightSplit[1])
inchesFromFeet = heightFeet*12
totalInches = inchesFromFeet + heightInches
print 'You are {0} inches'.format(totalInches)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120714/ed725ad5/attachment.html>


More information about the Tutor mailing list