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
  Try,Except,Else to check that user has entered either y or n (Code block pasted) RandomNameGenerator 3 255 Jun-29-2021, 08:21 PM
Last Post: RandomNameGenerator
  Unable to access the user input value given to daterangepicker klllmmm 1 486 May-26-2021, 09:16 PM
Last Post: nilamo
  Problem restricting user input in my rock paper scissors game ashergreen 6 906 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  Applying function mapypy 1 538 Mar-11-2021, 09:49 PM
Last Post: nilamo
  LinkedList by User Input SantiagoPB 5 971 Mar-03-2021, 09:54 PM
Last Post: deanhystad
  User input/picking from a list AnunnakiKungFu 2 552 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
  Defining a function with input abcd 5 717 Feb-21-2021, 02:34 AM
Last Post: NullAdmin
  Generate Random operator, take user input and validate the user mapypy 4 609 Feb-03-2021, 08:41 PM
Last Post: nilamo
  Code giving same output no matter the input. Yort 2 545 Dec-20-2020, 05:59 AM
Last Post: buran
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 918 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes

Forum Jump:

User Panel Messages

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