简体   繁体   English

为什么我的代码与我的计算器和在线计算器相比是错误的,有人可以告诉我它有什么问题吗

[英]Why is my code wrong incomparsion to my calculator and online calculators can someone let me know whats wrong with it

 from math import cos
 from math import  sin
 from math import pi
 a0 = int(input("a0:"))
 b0 = int(input("b0:"))
 N = int(input("N:"))
 L = int(input("L:"))
 X = int(input("X:"))
 n = 0
 an = a0
 bn = b0
 y=0
 for i in range(N):
    n = n+1
    an = an + 10   
    bn = bn * 10   
    y = an * (cos(((n*pi*X)/(L))))+ (bn*(sin((n*pi*X)/(L))))
 total = a0 + y
 print(total)

Im assuming that the y =.... code is wrong since the an and bn code works fine lmk Equation我假设 y =.... 代码是错误的,因为 an 和 bn 代码工作正常 lmk方程

Since this is a sum you need to be keeping track of that inside the loop.由于这是一个总和,因此您需要在循环内跟踪它。 Right now y will just be the result of that last iteration.现在y只是最后一次迭代的结果。

 from math import cos
 from math import  sin
 from math import pi
 a0 = int(input("a0:"))
 b0 = int(input("b0:"))
 N = int(input("N:"))
 L = int(input("L:"))
 X = int(input("X:"))
 n = 0
 an = a0
 bn = b0
 y=0
 for i in range(N):
    n = n+1
    an = an + 10   
    bn = bn * 10   
    y += an * (cos(((n*pi*X)/(L))))+ (bn*(sin((n*pi*X)/(L))))
 total = a0 + y
 print(total)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以告诉我合并排序的代码有什么问题吗? - Can some tell me whats wrong with my code for merge sort? 有人可以扫描我编写的这段 Python 代码并让我知道我做错了什么吗? - Can someone scan over this Python code that I wrote and let me know what I did wrong? 有人能告诉我我的代码有什么问题吗 - Can someone tell me what is wrong with my code 有人可以告诉我我的 animation 代码有什么问题吗? - Can someone tell me what's wrong with my animation code? 有人可以告诉我这段代码有什么问题吗 - Can someone please tell me whats wrong with this code 我的代码有什么问题? - Whats' wrong with my code? 嘿,有人能帮我找出我的代码有什么问题来解决欧拉问题 50(连续质数和),它只适用于低于一百 - hey,can someone help me to find out whats wrong with my code to solve Euler problem 50(Consecutive prime sum), its just work for below one-hundred 在Odoo 8我的代码有什么问题? - In Odoo 8 Whats wrong with my code? 有人可以告诉我我的代码有什么问题吗? 我在调试时遇到问题 - Can someone tell me what is wrong with my code? I am having problems debugging python 中的变量不起作用,有人可以告诉我我的代码有什么问题吗? - Variable in python not working, can someone tell me what is wrong with my code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM