我试图分配一个名为“ app_price_formula”的变量,以记住它必须执行if语句:
opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
app_price = 30
app_price_formula = if app_price > 30:
print('This app is expensive')
但是我得到这个错误
File "<ipython-input-1-da34fd0221c3>", line 7
app_price_formula = if app_price > 30:
^
SyntaxError: invalid syntax
答案 0 :(得分:1)
app_price_formula = (app_price > 30)
if app_price_formula:
print('This app is expensive')
第一条语句将True
或False
保存在变量中。根据变量的值,执行if语句。
答案 1 :(得分:1)
为什么不尝试像这样使用function
:
def app_price_forumula(app_price):
if app_price > 30:
return print("This app is expensive")
示例:
app_price_formula(40)
哪些印刷品:
"This app is expensive"
答案 2 :(得分:0)
尝试一下:
function pageSel2() {
var parseAmount2 = localStorage.getItem("amountKey");
var parseMonth2 = localStorage.getItem("monthKey");
document.getElementById("demo1").value = parseAmount2;
document.getElementById("demo2").value = parseMonth2;
}
function roundAmount() {
var x=document.getElementById("demo1");
x.value=Math.round(x.value/250)*250;
}
function roundMonth() {
var x=document.getElementById("demo2");
x.value=Math.round(x.value/12)*12;
}
pageSel2();