Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sentence maker help
#2
Your code has a number of problems. First, do not use 'is' for equality. The is operator tests identity, not equality. That is, are these the same object, not are these equivalent objects. Use the equality operator (==).

Second, you are using 'or' incorrectly. This:

if random.choice(an) == 'hate' or 'love':
is equivalent to:

if (random.choice(an) == 'hate') or 'love':
Due to order of operations. Non-empty strings like 'love' are treated as True in conditional expressions. So line 2 of your code will always be True, and will always trigger. The correct way to test multiple equalities like this is the 'in' operator:

if random.choice(an) in ('hate', 'love'):
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Sentence maker help - by bidoofis - Feb-08-2019, 02:49 AM
RE: Sentence maker help - by ichabod801 - Feb-08-2019, 03:36 AM
RE: Sentence maker help - by bidoofis - Feb-08-2019, 03:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with flowchart maker program bluebouncyball 2 761 Aug-08-2023, 10:25 PM
Last Post: deanhystad
  Label Maker FPDF, Reportlab jamesaarr 1 2,659 Aug-09-2021, 11:57 PM
Last Post: Pedroski55
  while sentence kimyyya 3 2,946 Mar-20-2021, 06:00 AM
Last Post: Pedroski55
  List / arrays putting in sentence Kurta 3 2,564 Dec-25-2020, 11:29 AM
Last Post: Larz60+
  How to make a telegram bot respond to the specific word in a sentence? Metodolog 2 6,352 Dec-22-2020, 07:30 AM
Last Post: martabassof
  How to match partial sentence in long sentence Mekala 1 1,524 Jul-22-2020, 02:21 PM
Last Post: perfringo
  Remove a sentence if it contains a word. lokhtar 6 5,900 Feb-11-2020, 04:43 PM
Last Post: stullis
  Regex Help for clubbing similar sentence segments regstuff 3 2,153 Nov-20-2019, 06:46 AM
Last Post: perfringo
  how to get all the possible permutation and combination of a sentence in python sodmzs 1 4,161 Jun-13-2019, 07:02 AM
Last Post: perfringo
  wont print last sentence.. mitmit293 2 2,361 Jan-27-2019, 05:38 PM
Last Post: aakashjha001

Forum Jump:

User Panel Messages

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