为什么它不会从if循环中输出产品

发布于 2025-01-24 02:16:13 字数 1387 浏览 1 评论 0原文

一切都起作用,但不会产生锻炼,并不断要求我从列表中输入技能。我想请用户输入技能,输出锻炼,并不断要求他们加入另一种技能。否则输入停止以打破循环。

skill4 = ['defense', 'finishing', 'athleticism', 'posting']

print('Focus on: \nDefense \nPosting \nAthleticism \nFinishing')

skill4 = str.lower(input('Select 1 skill you want to improve on the list: '))

while True:

   if work != skill4:

       skill4 = str.lower(input('Please select 1 skill from above: '))

   if work == skill4[0]:

       print (' \nYour exercises are: ')

       print('Lateral training 40 seconds \nShuffle on a line 40 seconds \nladder training: 40 seconds')

       if work == skill4[1]:

           print (' \nYour exercises are: ')

           print('Side hook: 10 makes (per side)\nScoop: 10 makes (per side)\nFloater: 10 makes (per side)')

           if work == skill4[2]:

               print (' \nYour exercises are: ')

               print('Run 7 miles per hour for 30 minutes (break each 15)\nJump squat: 40 seconds\nRope skipping: 1 min 30 sec')

               if work == skill4[3]:

                   print (' \nYour exercises are: ')

                   print('Up and under move (15 times)\nKobe fadeaway move (15 times)\nCut to short corner, receive pass from wing and shoot. (10 times) ')

                   if work == "stop":

                       break

                   else: skill4 = str.lower(input('Select another skill: '))

Everything works but it doesn't produce the workout and keep asking me to input the skill from the list. I want to ask the user to input the skill, output the workout and keep asking them to put another skill. Otherwise input stop to break out the loop.

skill4 = ['defense', 'finishing', 'athleticism', 'posting']

print('Focus on: \nDefense \nPosting \nAthleticism \nFinishing')

skill4 = str.lower(input('Select 1 skill you want to improve on the list: '))

while True:

   if work != skill4:

       skill4 = str.lower(input('Please select 1 skill from above: '))

   if work == skill4[0]:

       print (' \nYour exercises are: ')

       print('Lateral training 40 seconds \nShuffle on a line 40 seconds \nladder training: 40 seconds')

       if work == skill4[1]:

           print (' \nYour exercises are: ')

           print('Side hook: 10 makes (per side)\nScoop: 10 makes (per side)\nFloater: 10 makes (per side)')

           if work == skill4[2]:

               print (' \nYour exercises are: ')

               print('Run 7 miles per hour for 30 minutes (break each 15)\nJump squat: 40 seconds\nRope skipping: 1 min 30 sec')

               if work == skill4[3]:

                   print (' \nYour exercises are: ')

                   print('Up and under move (15 times)\nKobe fadeaway move (15 times)\nCut to short corner, receive pass from wing and shoot. (10 times) ')

                   if work == "stop":

                       break

                   else: skill4 = str.lower(input('Select another skill: '))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2025-01-31 02:16:13

在此行,

skill4 = str.lower(input('Select 1 skill you want to improve on the list: '))

您正在设置可变技能4,从而覆盖您的技能列表。因为 work 变量保持不确定,因此您将无法以后进行比较。

您也有一个凹痕问题。 if语句是嵌套的。因此,您仅检查工作== Skill4 [1]是否在工作== Skill4 [0]时,这是永远不可能的。

我看到的最后一个问题不是很明显,而是非常烦人:在此行中,

if work != skill4:

您检查选定的项目是否是有效的工作项目,但是您将其与列表进行比较,而不是检查它是否在列表中。您会这​​样做:

if work not in skill4:

希望这对您有所帮助!

on this line

skill4 = str.lower(input('Select 1 skill you want to improve on the list: '))

you are setting the variable skill4, thus overwriting your list of skills. Because the work variable stays undefined, you will not be able to compare it later.

You also have an indentation problem. The if statements are nested. Because of that, you only check if work == skill4[1] when work == skill4[0], which can never be true.

The last problem I see is not very noticable but very annoying: in this line

if work != skill4:

You check if the item selected is a valid work item, but you compare it to the list instead of checking if it is in the list. You would do that this way:

if work not in skill4:

I hope this helps you!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文