相同的输出在循环中重复

发布于 2025-02-08 18:09:14 字数 798 浏览 2 评论 0原文

为什么我的程序仅在终端中显示代码u = float(“输入字母'u':”的值)的行?)?

    B=0
    A=0
    U=0

    while(U == 0):
     
         U=float(input( "Enter the value of the letter 'U' :" ))
     
         ent=[200,101,255,11]

         for i in ent:
         
             A = A + (i * ( 1 -(1/10**2)  ) / 255)  -1/(10**2)

             B = B + i

    print(B)

该程序在终端中的输出是:

Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  9
4536

Process finished with exit code 0

Why does my program only show the line of code U=float(input( "Enter the value of the letter 'U' : " )) in the terminal?

    B=0
    A=0
    U=0

    while(U == 0):
     
         U=float(input( "Enter the value of the letter 'U' :" ))
     
         ent=[200,101,255,11]

         for i in ent:
         
             A = A + (i * ( 1 -(1/10**2)  ) / 255)  -1/(10**2)

             B = B + i

    print(B)

The output of the program in the terminal is this:

Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  0
Enter the value of the letter 'U' :  9
4536

Process finished with exit code 0

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

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

发布评论

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

评论(1

此岸叶落 2025-02-15 18:09:14

似乎您需要

通过再提供一个选项卡来修复“打印(b)”行上的凹痕,您每次用户输入某些内容时都会打印出来,并且使用一个选项卡,您将为数组中的每个值打印一个选项卡!

例如,通过将 print()内部的用于循环,将显示变量b 4次(由于 ent 变量)每次用户插入一个数字:

    B=0
    A=0
    U=0

    while(U == 0):
     
         U=float(input( "Enter the value of the letter 'U' :" ))
     
         ent=[200,101,255,11]

         for i in ent:
         
             A = A + (i * ( 1 -(1/10**2)  ) / 255)  -1/(10**2)

             B = B + i

             print(B)

it seems like you need to fix indentation on the "print(B)" line

By giving one more TAB you will be printing each time the user inputs something, and with one more TAB you will be printing for each value inside your array!

For example, by having print() inside the for loop, the variable B will be shown 4 times (due to the ent variable) each time the user inserts a number:

    B=0
    A=0
    U=0

    while(U == 0):
     
         U=float(input( "Enter the value of the letter 'U' :" ))
     
         ent=[200,101,255,11]

         for i in ent:
         
             A = A + (i * ( 1 -(1/10**2)  ) / 255)  -1/(10**2)

             B = B + i

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