私信  •  关注

Vaibhav

Vaibhav 最近创建的主题
Vaibhav 最近回复了
4 年前
回复了 Vaibhav 创建的主题 » 在Python中将多个输入项打印为一个显示

排队 return item_list 应该在for循环之外。请参阅以下代码:

def make_list():
    # Create an empty list.
    item_list = []
    # Add three item to the list.
    print('Enter data for three items: ')
    for count in range(1, 4):
        # Get item data.
        print('Item number ' + str(count) + ':')
        item = input('Enter description of item: ')
        units = float(input('Enter number of units in inventory: '))
        price = float(input('Enter price per item: '))
        print()

        # Creat new RetailItem and assign items variable.
        items = RetailItem(item, units, price)
        # Add items to list.
        item_list.append(items)

    return item_list
4 年前
回复了 Vaibhav 创建的主题 » Python中的“TypeError:__;对象不可订阅”以及如何修复它?

f1 是阶级的对象 Fila 因此你不能把它写下来或用作 f1[0]

4 年前
回复了 Vaibhav 创建的主题 » python中货币的if/then语句

你可以使用iter在熊猫排上进行测试 iter.rows() 并进行计算。请参阅以下代码:

for index, row in df.iterrows():
    if row['Currency'] == 'EUR':
        row['Price'] = row['Price'] * 1.10 
    elif row['Currency'] == 'CHF':
        row['Price'] = row['Price'] * 1.08 
    elif row['Currency'] == 'DKK':
        row['Price'] = row['Price'] * 0.15 
    elif row['Currency'] == '£':
        row['Price'] = row['Price'] * 1.32
    else:
        row['Price' ]= row['Price']
6 年前
回复了 Vaibhav 创建的主题 » 如何使用python/json输入在数据之间插入数据?

以下是解决方案:

import json

with open("intents_kor.json") as file:
    data = json.load(file)

a = input('input a : ')
b = input('input b : ')

data['intents']={'tag': 'not_in_json', 'patterns': [a], 'responses': [b], 'context_set': ''}
print(data)
7 年前
回复了 Vaibhav 创建的主题 » 如何使用anaconda提示符安装python的“os”包?[复制品]

os 已随python包一起安装。只需将其导入到python文件中,就可以通过 import os .