我有一个有两个选项卡的工作表,我想让一个VBA自动运行,并弹出一个窗口消息说"NPV为负!请输入未来的储蓄!“任何时候单元格J27 (在两个选项卡中)计算负值。我在模块中有以下代码,当我测试并单击run时,它会做我想做的事情,但实际上,当我更改信息并且单元格J27为负数时,什么也不会发生。我是VBA的新手,所以任何帮助都是非常感谢的。
Private Sub Worksheet_Calculate()
For Each cell In Range("J27")
If cell.Value < 0 Then MsgBox ("NPV negative
我的代码是-
def factorial(number):
result = 1
while number > 0:
result = result*number
number = number- 1
return result
in_variable = input("Enter a number to calculate the factorial of")
print factorial(in_variable)
我在行上得到一个缩进错误:
number = number- 1
我的错误是:Unexpected indent
为什么会这样呢?
致以敬意
我正在做一个小程序来评估两个矩形的面积。用户输入矩形的长度和宽度(我的第一个模块),然后程序计算矩形的面积(第二个模块),最后在计算两个区域之间的差值后,显示结果,告诉哪个是较大的。
但是,输入长度和宽度后,程序将显示一条错误消息,告知我的模块未定义为:
ImportError: No module named 'inputRect'
我的守则:
#Project M04: Rectangle with the bigger area
#Python 3.4.3
#Module that asks width and lenght of the two rectangles
我正在编写一个简单的java程序,使用Multiplication面向对象的技术来执行添加、和。首先询问运算的加法、乘法或退出。当按下“加法和乘法”按钮时,它从用户处得到两个数字,执行任务,并给result.But my 问题--当按“退出”按钮时,它不会终止,而是请求编号。
我想问的第二件事是,我是否遵循面向对象的方法。
import javax.swing.JOptionPane;
public class Calculator {
private static int number1;
private static int number2;
public static void se
首先,我对编程非常陌生,所以请耐心等待。我的当前代码有以下问题,我无法解决。我无法根据用户输入获取end to循环。现在,代码返回一个名称错误。有人知道我怎么解决这个问题吗?谢谢您抽时间见我。
def gcd(a,b):
start_over = "true"
while start_over == "true":
while True:
a = int(input("Enter your first positive whole number: "))
继续运行这个错误,但我很困惑,因为理论上,在将变量作为参数通过函数发送之前,我已经验证了该变量为整数。有什么想法吗?谢谢!
问题是:"calculate_distance(n):“,它不喜欢我在这些值中使用"<>”运算符。
print("Welcome Astronaut to Apollo 11 - the mission to land on The Moon.")
print("Lets determine the length of your journey so far - It should take about 3 days t
n = int(input("Enter the binary number : "))
n_into_str = str(n)
lenf = len(n_into_str)
def calculate(n):
ans = 0
for i in range(lenf):
z = n%10
power = 2**i
k = z*power
value = z
ans = ans + z
print(ans)
calculate(n)
我寻找LCM的功能不起作用。while循环有问题吗?
x = int(input("Enter the first number"))
y = int(input("Enter the second number"))
def calculate_LCM(x,y):
if (x>y):
max=x
else:
max=y
while((max%x==0) and (max%y==0)):
print(max)
max=max+1
from collections import deque
def window(seq, n=2):
it = iter(seq)
win = deque((next(it, None) for _ in xrange(n)), maxlen=n)
yield win
append = win.append
for e in it:
append(e)
yield win
a=[1,2,3]
b=[2,4,6]
for d in zip(window(a,2),window(b,2)):
print d
作为初学者,我用Python编写了我的第一个程序(计算器),就功能而言,它工作得很好,但在代码的末尾,我对一件事有些顾虑。在CalculateAgain()中的if语句中,Calculate()没有return语句。如果我使用它,它只运行一次函数,然后退出程序。这就是为什么我没写口供的原因。这样可以吗?我应该换点东西吗?
#Choose the operation
def OperationType():
while True:
Type = input('What type of operation do you want? +, -, *, /: \n&
我正在为一个高尔夫球场写一个用户界面,其中有一个文本文件,里面有联盟中球员的名字。用户输入每个球员在9洞的得分,并返回每个球员的总得分、标准杆和小鸟球。我收到这个错误:
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
main()
File "/Users/tinydancer9454/Documents/python/golfRound.py", line 101, in main
enterScores(l,
我只是在编写一个Python程序,它接受两个整数并返回和。我遇到的问题是终端从来不显示返回的值,所以我不得不使用打印语句。有任何方法让终端显示程序的返回值吗?
守则如下:
import argparse
def simple_addition():
parser = argparse.ArgumentParser(description = "Simple Addition Program to Test CLI")
# each line add AN argument to our terminal inout
parser.add_argume
OK -我正在尝试让一个Python函数接受来自另外两个函数的变量。这是可能的吗?
下面是我正在尝试做的一个示例(我已经简化了原始代码-在这里输入)。希望你能明白我想要做什么。简而言之,我有调用Extras()的Rectangle (),我希望把Rectangle和Extras的输出发送到Calculate_Deposit ()。
这是可能的吗?
def calculate_deposit(total_cost, extras):
deposit_percent = float(raw_input("Enter Deposit % (as a decimal) of Total
我似乎在使用sublimeREPL运行python代码时遇到了问题,用户输入了崇高的文本2。我有一段可以在命令提示符中使用的代码,不能在REPL中执行。错误似乎是REPL无法处理输入的格式并假设它是字符串。我的python是相当有限的,所以是否有一种方法可以让REPL对我的代码很好,或者我需要指定输入?
注意:每次将tempInput转换为int将有效,但很繁琐。
“守则”:
# Matthew P
# A program to calculate average grades
def avg(total, elements):
return total / elements
te
def get_list():
print('enter the list of integers on a single line, separated by comma, enter to end: \n')
num1 = [int(i) for i in input().split(',')]
return num1
def calculate(n1, n2, length):
n3=list()
for i in range(0, length(n1)):
n3.append(n1[i]+n2[i
def Get_Details():
Student_Name = input("Enter the name of the student: ")
Coursework_Mark = int(input("Enter the coursework mark achieved by the student: "))
while Coursework_Mark < 0 or Coursework_Mark >60:
print("Try again, remember the coursework mar
当我运行我的计算器,它给出以下结果;
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4):3
Enter first number: 1
Enter second number: 5
Invalid! Input
有谁能向我解释一下为什么它要用else语句来响应,我已经检查了代码很多次了,而且在经历了很多挫折之后,我已经直接复制了代码,但是结果是一样的?
# A simple calculator that can add, subtract, multiply and divide.
#
每当我键入"no“表示”您想要找到另一个形状的区域吗?“它又问了我一个问题。这是我的密码:-
def calculate_area():
print "Welcome to the area calculator"
user= raw_input("Enter the shape you would like to calculate the area of:").lower()
def restart():
answer= raw_input( "Would you like to find the area of ano
我创建了一个简单的程序,使两个数字之和,但是..。这个程序反而是连在一起,这太让人困惑了!有人能帮忙吗?
function calculate() {
var numberOne = document.querySelector(".first").value;
var numberTwo = document.querySelector(".second").value;
var sum = numberOne + numberTwo;
document.querySelector(".result").innerHTML
任务是不使用数组输出每一行的平方和和。我编写了一个代码,它完成了这项工作,只是我找不到一种方法允许根据第一个输入(即矩阵的大小)对矩阵进行动态调整,这样用户就可以像在实际的矩阵中那样,在每个元素之后按下'enter',而不是按'enter‘来分隔每个元素,并用’enter‘分隔行。如果有办法,请告诉我。下面是需要在每个元素之后按下'enter‘的代码。
/*Take matrix size as input. read each element and give out the sum of squaresum of rows of the matrix*/
#
我需要找到两个学生的平均成绩,最后一行应该显示最高的平均成绩和学生的名字。这就是我所拥有的,无法弄清楚我错过了什么.
def main ():
names= ("Rebecca", "Jennifer")
Welcome()
for name in names:
grade= totalgrade(name)
highestgrade()
if (totalgrade < grade_average):
grade_average= totalgrade
创建一个日历程序,允许用户在三个独立的变量中输入日、月和年,如下所示。
Please enter a date
Day:
Month:
Year:
然后,要求用户使用以下格式从选项菜单中进行选择:菜单:
1) Calculate the number of days in the given month.
2) Calculate the number of days left in the given year.
该程序必须包括以下函数: leap_year:将年份作为参数,如果年份是闰年,则返回1(链接到外部站点)。如果不是,则为0。此信息仅供其他函数使用。number
我一直在尝试解决一个程序:计算数字的阶乘中尾随零的数量,这是我的代码。它在我的PC上运行得很好,但在judge上运行时显示“运行时错误(NZEC)”。
def fact(n):#calculate factorial of the number
i =2
temp =1
while i<= n :
temp*=i
i+=1
return temp
def zero_count(n):#calculate number of trailing zeroes
F = fact(n)
F =str(F)
R = F[::-1]
Rn
*这个计算器只适用于一位数的计算。
在我的代码中,有3个文本框,两个用于值,一个用于运算符。
我希望,如果第一个文本框不是空的,并且用户单击超过该值的任何数字,则应该在另一个文本框中添加该值。
当我单击Enter时,它不会显示结果,也不会在控制台中显示任何错误
// Textboxes, Enter and Reset
var txt1 = document.querySelector("#txt1");
var txt2 = document.querySelector("#txt2");
var txt3 = document.que
我正在尝试编写一个函数来使用以下公式计算二项式系数:
我遇到的问题是我无法得到正确的答案。这是我尝试编写该函数的两种方法的一个示例。
def binomial(n, i):
total = 0
for j in range(1, (n-i+1)):
n = float(n)
i = float(i)
j = float(j)
product = (i+j) / j
if total == 0:
total = product
els
我目前正在尝试制作一个非常基本的随机数游戏。一切似乎都在按它应该的方式工作,减去了数学上不合理的事实。你有3个选项: 1)攻击,2)治疗,3)退出游戏。每一个函数都按预期运行,并显示了预期的结果,减去了数学运算不合理的事实。 --------------------- Beau hit the monster for 10 damage! The Monster hit Beau for 18 damge! You now have 81 health points! The monster now has 80 health points! --------------------- 老实
我正在使用的Python教程书有点过时了,但我决定继续在最新版本的Python中使用它来练习调试。有时,我了解到书中代码中的一些内容在更新后的Python中发生了更改,但我不确定这是不是其中之一。
虽然修复程序使其可以打印更长的阶乘值,但它使用长int来解决问题。原始代码如下:
#factorial.py
# Program to compute the factorial of a number
# Illustrates for loop with an accumulator
def main():
n = input("Please enter a whole
我的文档包含用于生产的部分,我的很多数据来自于我的公司的数据仓库查询。
问题是:
当我更新查询/文档时,拥有我的VLOOKUPNTH公式的所有单元格都会显示值"#value",直到我手动单击公式栏并按enter。那它就完美了。
问题是,一旦我更新我的程序,我必须手动按下每个单元格这个函数,并按回车在功能条(它大约是15x3单元)。
我的代码:
Function VLOOKUPNTH(Lookup_value, table_array As Range, _
Col_index_num As Integer, Nth_value)
' Extension to VLOO