Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic code help
#1
Hey there, trying to run a basic Boolean program however I'm having trouble printing one of my options.
I want to print "True" for values equal to 0.1 or greater than 1.0 and "False" for anything in between.
The only option that won't print is the case where the value is greater than 1.0.

Here's the code:
value = 1.5

if value == 0.1:
   print("True")
elif value >0.1:
   if value <1.0:
       print("False")
else:
   print("True")
Thanks for the help!
Reply
#2
Quote:I want to print "True" for values equal to 0.1 or greater than 1.0 and "False" for anything in between.

You are over complicating it. All you need to do is check your true values, and if not that then its false. 

value = 1.5

if value == .1 or value > 1:
    print('True')
else:
    print('False')
Recommended Tutorials:
Reply
#3
A simplified version of metulburr's code if you wanna be super pro...
print value == .1 or value > 1
(This is assuming that nothing funky will happen printing a boolean instead of a string, since they do both have the same string representation.)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 566 May-21-2024, 03:58 PM
Last Post: CandleType1a
  List index out of range error when attempting to make a basic shift code djwilson0495 4 3,213 Aug-16-2020, 08:56 PM
Last Post: deanhystad
  Writing a basic shift code djwilson0495 2 2,393 Aug-16-2020, 01:52 PM
Last Post: djwilson0495
  Problem with Basic Rock Paper Scissors code BirinderSingh 3 2,654 Sep-13-2019, 03:28 PM
Last Post: ichabod801
  basic code help chche5 4 5,628 Feb-17-2018, 10:24 PM
Last Post: chche5
  Basic Doubt in code prateek3 6 5,137 Aug-19-2017, 01:05 PM
Last Post: ichabod801
  Need help with basic code Random 6 5,174 Feb-08-2017, 04:56 AM
Last Post: tannishpage

Forum Jump:

User Panel Messages

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