If…else statement issue with raw_input on Python

前端 未结 2 1221
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 23:41

I\'m currently following Zed Shaw\'s book on Python, Learn Python the Hard Way and I\'m learning about functions. I decided to follow some of the extra credit exercises that

2条回答
  •  余生分开走
    2020-12-11 23:49

    In Python 2.x raw_input returns a string. Looking at your code, you could also use input which returns an integer. I would think that would be the most explicit option using Python2.

    Then you can treat food as an int throughout your code by using %d instead of %s. When entering a non int your program would throw an exception.

提交回复
热议问题