0
import random
import sys


def v1_debug(v1, subject):
    if v1 != str and subject != str:
        sys.exit()
    else:
        if subject == 'He' or 'She' or 'It':
            for i in v1:
                if i == [len(v1)+1]:
                    if i == 's' or 'z' or 'x' or 'o':
                        v1 = v1 + 'es'
                    elif i == 'y':
                        v1 = v1 - 'y' + 'ies'
                elif v1[len(v1)] == 's' and v1[len(v1)+1] == 'h':
                    v1 = v1 + 'es'
                elif v1[len(v1)] == 'c' and v1[len(v1)+1] == 'h':
                    v1 = v1 + 'es'
        if subject == 'I' or 'You' or 'We' or 'They':
            for i in v1:
                if i == v1[len(v1)+1]:
                    v1 = v1 + 'ing'
    return ''


def default_positive_form():
    try:
        sbj = ['He',
               'She',
               'It',
               'I',
               'You',
               'We',
               'They']
        v1 = ['be',
              'beat',
              'become',
              'begin',
              'bend',
              'bet',
              'bid',
              'bite',
              'blow',
              'break',
              'bring',
              'build',
              'burn',
              'buy',
              'catch',
              'choose',
              'come',
              'cost',
              'cut',
              'dig',
              'dive',
              'do',
              'draw',
              'dream',
              'drive',
              'drink',
              'eat',
              'fall',
              'feel',
              'fight',
              'find',
              'fly',
              'forget',
              'forgive',
              'freeze',
              'get',
              'give',
              'go',
              'grow',
              'hang',
              'have',
              'hear',
              'hide',
              'hit',
              'hold',
              'hurt',
              'keep',
              'know',
              'lay',
              'lead',
              'leave',
              'lend',
              'let',
              'lie',
              'lose',
              'make',
              'mean',
              'meet',
              'pay',
              'put',
              'read',
              'ride',
              'ring',
              'rise',
              'run',
              'say',
              'see',
              'sell',
              'send',
              'show',
              'shut',
              'sing',
              'sit',
              'sleep',
              'speak',
              'spend',
              'stand',
              'swim',
              'take',
              'teach',
              'tear',
              'tell',
              'think',
              'throw',
              'understand',
              'wake',
              'wear',
              'win',
              'write']
        sbj = random.choice(sbj)
        v1 = random.choice(v1)
        verb_debug = v1_debug(v1, sbj)
        sen = ''
        if sbj == 'I':
            sen = sbj + 'am' + verb_debug
        elif sbj == 'He' or 'She' or 'It':
            sen = sbj + 'is' + verb_debug
        elif sbj == 'You' or 'We' or 'They':
            sen = sbj + 'are' + verb_debug
        print(f'{sen}')
    except NameError:
        print('this is bullshit')
    return

default_positive_form()

this is python 3.8

roganjosh
  • 12,594
  • 4
  • 29
  • 46
  • Note that part of a good [mre] is that it be *minimal* -- that it be the shortest possible code that creates the same problem. Surely there's no need to include the full word lists. Heck, you could probably eliminate the use of random choice altogether and still be able to demonstrate the problem. – Charles Duffy Jun 07 '20 at 19:09
  • What do you think `if v1 != str and subject != str` does? Hint: It's not checking whether those variables _are_ strings; it tests whether they _point to the `str` type constant_. – Charles Duffy Jun 07 '20 at 19:13
  • ...anyhow, this is part of why just calling `sys.exit()` without printing any debugging beforehand is a general bad idea; it doesn't give you any clues about _why_ your program exited. Better to raise an exception when you have an error. – Charles Duffy Jun 07 '20 at 19:15

1 Answers1

0

sen will only consist of an empty string if none of the conditions of your if/elif/elif blocks are met. Change the print line to

print(f"sen is: {sen}")

But that's not the real problem. obj != str does not check if obj is a string, it checks to see if the object is pointing to the type constant str (Thanks Charles Duffy for the comment). Instead, use the builtin function isinstance() like so:

if not isinstance(v1, str) and not isinstance(subject, str):
    print("Variables are the wrong type!")
    sys.exit()
MattDMo
  • 100,794
  • 21
  • 241
  • 231