(Apr-20-2020, 03:40 AM)deanhystad Wrote: There is no reason the word can't be a string. The word doesn't change.
hi @deanhystad
i have basically taken apart the wheel of fortune HANGMAN code you sent. Since i am just stating off in python it took me a while. But i learnt quite a few things which is uniquely interesting about python, specially list comprehension.
And i have understood that strings cannot be re-assigned as per index. Even in the code the string is converted into a list(array) and dealt with therein. while strings have a great many functions, it is not possible to reassign a character in the string by index.
Please let me know if you think otherwise.
Error:Traceback (most recent call last):
File "C:/Study/App1_1/Study2.py", line 15, in <module>
b[i] = x
TypeError: 'str' object does not support item assignment
(Apr-24-2020, 02:13 AM)Shahmadhur13 Wrote: I have made hangman with little more interactive and can play over and over.
@Shahmadhur13 thank you for the code. i must say you have maintained most of the operation as a string.
it is quite interactive.
you have put in a lot of effort for the code. During my lessons i read somewhere its best to keep code to minimum. while your code internal logic is approx 30 lines. The code sent by @deanhystad is only 10 lines.
i am not counting the interactive menu code. if i understand correctly you have used all the string functions to create this program, which is why it is long. but in assigning the index you have used a list(array). so if you start using the letters and words as array elements from the beginning, you could save a lot of code lines.
this is just my observation. each persons logic is unique.
let me know what you think.