Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable in range of float
#1
Noob here just a few weeks in, So after all the reading and videos I decided it was time to do more writing.
I got side tracked and somehow ended up trying to take a variable and turn it into a float that I could check to see if it was between two floats values.
I seen where someone used pylab frange for something and got it to work right I think. Keep in mind I m very new. How do I clean this up or make a function,
Where do I go from here or put it to use....

import pylab as pl

# range scale to determine outcome of a weighted purchase
avg_screwed = pl.frange(0.00,6.0,0.1)
avg_below = pl.frange(6.0,7.0,0.1)
avg_weight = pl.frange(7.0,7.50,0.1)
avg_above = pl.frange(7.50,8.0,0.1)
avg_extreme = pl.frange(8.0,99.0,0.1)

#get users purchase weight input
user_weight = float(input('What was the weight: '))
#possible outcomes to inform the user of there purchase worth
if user_weight in avg_weight:
   print("You money was well spent.")
elif user_weight in avg_above:
   print('Nice, You did really well!')
elif user_weight in avg_extreme:
   print("WOW! Someone liked you.")
elif user_weight in avg_below:
   print('You have been shorted.')
elif user_weight in avg_screwed:
   print('Turn around and bend over!!!!!!')
else:
   print('I do not understand.')
Reply


Messages In This Thread
Variable in range of float - by dogginky - Dec-27-2017, 04:28 AM
RE: Variable in range of float - by Larz60+ - Dec-27-2017, 05:22 AM
RE: Variable in range of float - by dogginky - Dec-27-2017, 06:13 AM
RE: Variable in range of float - by Larz60+ - Dec-27-2017, 02:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 383 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  matplotlib x axis range goes over the set range Pedroski55 5 3,275 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Define a range, return all numbers of range that are NOT in csv data KiNeMs 18 7,150 Jan-24-2020, 06:19 AM
Last Post: KiNeMs
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,426 Jul-25-2019, 11:32 PM
Last Post: scidam
  Inclusive (closed) range with float numbers mapg 4 4,046 Apr-27-2019, 09:09 PM
Last Post: Gribouillis
  Variable Range Trinx 4 2,766 Jan-10-2019, 03:48 AM
Last Post: Trinx
  Would like to input a date variable and determine whether it is within the time range harold 3 2,609 Jan-05-2019, 09:04 AM
Last Post: Gribouillis
  Modifying / extracting multiple list items simultaneously using variable from range ehammarlund 4 3,742 Dec-06-2017, 08:15 PM
Last Post: ehammarlund

Forum Jump:

User Panel Messages

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