Python Forum
else condition not called when if condition is false
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
else condition not called when if condition is false
#8
(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.
Reply


Messages In This Thread
RE: else condition not called when if condition is false - by Sandz1286 - Apr-28-2020, 10:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 438 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  unable to remove all elements from list based on a condition sg_python 3 524 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 786 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Multiple variable inputs when only one is called for ChrisDall 2 534 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  Sent email based on if condition stewietopg 1 918 Mar-15-2023, 08:54 AM
Last Post: menator01
  Replacing values ​​in Mysql with a condition stsxbel 0 662 Mar-05-2023, 08:20 PM
Last Post: stsxbel
  Couldn't install a go-game called dlgo Nomamesse 14 3,266 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  create new column based on condition arvin 12 2,422 Dec-13-2022, 04:53 PM
Last Post: jefsummers
Question Running an action only if time condition is met alexbca 5 1,394 Oct-27-2022, 02:15 PM
Last Post: alexbca
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 882 Sep-08-2022, 06:32 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

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