Python Forum
Hi, I need help with defining user's input and applying it to code. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Hi, I need help with defining user's input and applying it to code. (/thread-27849.html)



Hi, I need help with defining user's input and applying it to code. - jlmorenoc - Jun-24-2020

import sys
from cs50 import get_string
from cs50 import get_int
from py_thesaurus import Thesaurus


def main():
   if len(sys.argv) != 2:
       print("Usage:python final.py read [or] thes")
       sys.exit(1)
ui = string(sys.argv[1])

if ui == "read"
   T = get_string("Enter Text: ")
   DG = get_int("What grade do you need? ")
   length = len(T)
   letters = 0
   S = T.count('.') + T.count('!') + T.count('?')
   W = T.count(' ')
   for i in range(length):
       if (T[i].isalpha()):
           letters += 1
   L = letters / W * 100
   S = S / W * 100
   calculate = 0.0588 * L - 0.296 * S - 15.8
   indexi = round(calculate)
   if (indexi == DG):
       print("You're right on!")
   if (indexi < DG):
       print("You need more. :( Consider longer words, sentences and/or paragraphs")
   if (indexi > DG):
       print("You passed your grade. Congrats!")



if ui == "thes"
   input_word = get_string("Word-")
   synonym = (input_word.get_synonym) 
   synonym_verb = (input_word.get_synonym(pos='verb'))
   synonym_adj = (input_word.get_synonym(pos='adj'))
   definition = (input_word.get_definition())
   antonym = (input_word.get_antonym())

   i = 0
   while i < 1: 
       print(f{synonym})
       print(f{synonym_verb})
       print(f{synonym_adj})
       print(f{definition})
       print(f{antonym})
       i += 1


if __name__ == "__main__":
   main()
Error:
#but I always get this error message:  File "final.py", line 13    if ui == "read"                  ^ SyntaxError: invalid syntax



RE: Hi, I need help with defining user's input and applying it to code. - ndc85430 - Jun-24-2020

You're missing the colon at the end of line 13. By the way, is your indentation correct?


RE: Hi, I need help with defining user's input and applying it to code. - pyzyx3qwerty - Jun-24-2020

The error message you get indicates that you haven't added the colon : at the end of the if statement on line 13, which results in the display of the error message.