Python Forum
Hi, I need help with defining user's input and applying it to code.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hi, I need help with defining user's input and applying it to code.
#1
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
Reply
#2
You're missing the colon at the end of line 13. By the way, is your indentation correct?
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 136 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  Help with User Interface design code ai_masti 0 58 Nov-19-2020, 05:58 PM
Last Post: ai_masti
  Repeating lines of code by an input Josh_Albanos 3 382 Oct-15-2020, 01:04 AM
Last Post: deanhystad
  Applying Moving Averages formula to a number lynnette1983 1 318 Sep-29-2020, 10:21 AM
Last Post: scidam
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 353 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  How to time a user's input Tbot1000 2 278 Aug-31-2020, 09:39 PM
Last Post: Larz60+
  converting user input to float troubles RecklessTechGuy 3 397 Aug-17-2020, 12:41 PM
Last Post: deanhystad
  Validating user input WJSwan 2 360 Jul-06-2020, 07:21 AM
Last Post: menator01
  My code is giving my an output of zero, no matter what value I input PiyushBanarjee 1 369 Jul-01-2020, 04:34 AM
Last Post: bowlofred
  if the input is not number, let user input again teatea 14 969 Jun-02-2020, 07:03 PM
Last Post: ibutun

Forum Jump:

User Panel Messages

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