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.
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  data input while debugging causes unwanted code completion fred1232 2 2,688 Sep-14-2025, 03:32 PM
Last Post: deanhystad
  auto applying for jobs alextony85 8 3,858 Sep-10-2025, 10:51 AM
Last Post: alextony85
  How to revert back to a previous line from user input Sharkenn64u 2 3,184 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  User input with while loops chizzy101010 2 12,608 Aug-25-2024, 06:00 PM
Last Post: chizzy101010
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 3,708 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 2,892 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  restrict user input to numerical values MCL169 2 2,562 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 2,909 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 3,131 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 3,267 Dec-11-2022, 07:39 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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