why does it say Syntax,Error: invalid syntax at line 5

257 Views Asked by At
from random import*
def saisie():
    ch1=""
    for i in range (1,9):
        ch1[i]=chr(randint(ord'A',ord'Z'))
        ch1=ch1+ch1[i]
    return ch1 

i wanted to get a word randomly selected with capital and 8 letters

1

There are 1 best solutions below

2
aramcpp On

ord is a function, so you should change your code like this

from random import*
def saisie():
    ch1=""
    for i in range (1,9):
        ch1[i]=chr(randint(ord('A'),ord('Z')))
        ch1=ch1+ch1[i]
    return ch1

UPD as @John Coleman said there is still bugs in code

  1. index will be out of bounds
  2. string are immutable so you can't assign by index

here is the working example

from random import*
def saisie():
    ch1=""
    for i in range (8):
        ch1 += chr(randint(ord('A'),ord('Z')))
    return ch1