python 3.x - Values are not equal when they should be -


here snippet of code asking user input. issue evaluation of current month. if current month input, gooddate should = 0. reason not evaluating equal. tried making variables integers strings, 08 doesn't equal 08 current month reason. let me know if isn't clear enough.

#!/usr/bin/python3 import time month = str(time.strftime("%m"))  # user input print("""starting time time format - month/day hours:minutes - example 7/21 08:00 option - leave month out, keep /  - example  /21 08:00""") date1 = input("enter starting time ->  ",)  # split / x = date1.split('/')  # evaluate if current month user entered. print("x value=", x[0]) print("month value=", month)  if month == x[0]:     gooddate1 = 0 else:     start_replacement1 = month+date1 gooddate1 = 1  print("gooddate value=", gooddate1) 

the problem appears forgot indent second last line: gooddate1 = 1. right gooddate1 aways 1 instead of 0.

you can use ==. if month == x[0] fine way compare strings.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -