我一直在网上搜索一段时间,似乎找不到任何东西.我基本上学习了几种语言,我只是想用不同的语言重新创建一个程序.
def read_one_file():
f = open('C:\Python27\inventory.dat', 'r')
invid = f.readline()
stock = f.readline()
published = f.readline()
price = f.readline()
invtype = f.readline()
title = f.readline()
author = f.readline()
return invid, stock, published, price, invtype, title, author
read_one_file()
print "Update Number In Stock"
print "----------------------"
print "Item ID: ", invid
Run Code Online (Sandbox Code Playgroud)
基本上我是在尝试读取文件,将数据吸收到变量中然后将这些变量传递给main(类?).当我归还它们时,它们仍然无法打印.当我在read_one_file之外初始化它们时,它们仍然没有返回正确的东西.
我正在尝试学习几种语言,因此我在不同语言上也会遇到同样的问题.这是我的代码:
def read_one_file():
with open('C:\Python27\inventory.dat', 'r') as f:
invid = f.readline().strip()
invtype = f.readline().strip()
price = f.readline().strip()
stock = f.readline().strip()
title = f.readline().strip()
author = f.readline().strip()
published = f.readline().strip()
return invid, invtype, price, stock, title, author, published
def write_one_file(holdId, holdType, holdPrice, holdStock, holdTitle, holdAuthor, holdPublished):
with open('C:\Python27\inventory.dat', 'w') as f:
invid = holdId
price = holdPrice
newstock = holdStock
published = holdPublished
f.write("Item Id: %s\n" %invid)
f.write("Item Type: %s\n" %holdType)
f.write("Item Price: %s\n" %price)
f.write("Number In Stock: %s\n" %newstock)
f.write("Title: …Run Code Online (Sandbox Code Playgroud) 这是我的代码的开头:
public partial class Form1 : Form
{
static Random random = new Random();
int prevnum;
int currentnum;
public int GenerateRandomNumber()
{
return random.Next(1, 1000);
}
public Form1()
{
int randomNumber = random.Next(1, 1000);
InitializeComponent();
}
private void enterButton_Click(object sender, EventArgs e)
{
currentnum = Convert.ToInt32(guessBox.Text);
if (randomNumber < currentnum)
{
warmOrColdLabel.Text = "Too High";
if (currentnum > prevnum)
{
guessBox.BackColor = Color.Blue;
prevnum = currentnum;
}
else
{
guessBox.BackColor = Color.Red;
prevnum = currentnum;
}
}
if (randomNumber > …Run Code Online (Sandbox Code Playgroud)