我从instagram上的Python_脚本获得的简单货币转换程序出错

我从instagram上的Python_脚本获得的简单货币转换程序出错,python,Python,我一直在python中转换货币的代码中遇到这个令人讨厌的错误 此代码来自instagram上的python_脚本。一切都在检查中,但这个小虫子正在阻止节目。我做错了什么或我做错了什么 这就是弹出的错误 文件C:/Users/Pig Toy的PC/Documents/PythonPrograms/currencyconverter.py,第70行 +&to_currency=toCur+&apikey=+apikey ^ SyntaxError:无效语法 我运行了所有其他函数,它们都已签出 """

我一直在python中转换货币的代码中遇到这个令人讨厌的错误

此代码来自instagram上的python_脚本。一切都在检查中,但这个小虫子正在阻止节目。我做错了什么或我做错了什么

这就是弹出的错误


文件C:/Users/Pig Toy的PC/Documents/PythonPrograms/currencyconverter.py,第70行 +&to_currency=toCur+&apikey=+apikey ^ SyntaxError:无效语法

我运行了所有其他函数,它们都已签出

"""
Created on Sun May 19 17:15:47 2019

@author: ArtOfDHT
"""

#real time currency conversion.

#importing necessary packages
import requests 
import tkinter as tk 
from tkinter import *
from tkinter import ttk

#list of currencies

currencylist = [ 'AED', 'AUD', 'BHD', 'BRL', 'CAD',
                'CNY' , 'EUR', 'KHD' , 'INR' , 'USD' ]

#defining inputs and widgets for GUI

def CreateWidgets():
    inputAMTL = label(root, text="Enter The Amount:", bg="SpringGreen4")
    inputAMTL.grid(row=1, column=2, columnspan=2, pady=10)

    inputAMTxt = Entry(root, width=20, textvariable=getAMT)
    inputAMTxt.grid(row=1, column=3, columnspan=2, pady=10)    

    fromLabel = Label(root, text="FROM:", bg="SpringGreen4")
    fromLabel.grid(row=2, column=1)

    root.fromCombo = ttk.Combobox(root, values=currencyList)
    root.fromCombo.grid(row=2, column=2)

    toLabel = Label(root, text="TO:", bg="SpringGreen4")
    toLabel.grid(row=2, column=3)

    root.toCombo = ttk.Combobox(root, values=currencyList)
    root.toCombo.grid(row=2, column=4)

    convertButton = button(root, text="Convert", width=52, command=Convert)
    convertButton.grid(row=3, column=1, columnspan=2, pady=50)

    outputANTL = label(root, text ="Converted Amount:", font=('Helvetica', 10),bg="SpringGreen4")
    outputANTL.grid(row=4, column=2, columnspan=2, pady=50)

    root.outputAMTAns = Label(root, font=("Helvetica", 20),bg="SpringGreen4")
    root.outputAMTans.grid(row=4, column=3, columnspan=2, pady=50)

def Convert():
    #fetch and storing user-input in responsive variables 
    inputAmt = float(getAmt.get())
    fromCur = root.fromCombo.get()
    toCur = root.toCombo.get()

    #storing API key

    apikey ="FP6UEQWASCREGU57"

    #storing the base URL

    baseURL = r"http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE"

    #storing the inputs
    inputURL = baseURL + "&to_currency=" + toCur + "&apiKey" + apiKey

    #return requests 
    inputURL = baseURL + "&from_currency=" + fromCur\
                + "&to_currency=" toCur + "&apikey=" + apiKey

    #response return
    requestObj = requests.get(inputURL)

    #converting the json format data to Python 
    result = requestObj.json()

    #getting the exchange rate 
    exchangeRate = float(result["Realtime Currency Exchange Rate"]
                                              ['5, Exchange Rate']

    #calculate the converted amount and rounding to nearest 2 places
    calculateAmt = round(inputAmt * exchangeRate, 2)

    #Display the converted amount in the respected label 
    root.outputAMTAns.config(text=str(calculateAmt)) 

    #creating root class 
    root = tk.Tk()

    #setting gui structure
    root.geometry("400x250")
    root.resizable(False, False)
    root.title("PyCurrencyConverter")
    root.config(bg = "SpringGreen4")

    #Create tkinter variable 
    getAMT = StringVar()

    #Calling the CreateWidgets() function
    CreateWidgets()

    #defining infinite loop to run app
    root.mainloop() ~~~~



This is the error that pops up.


 File "C:/Users/Pig Toy's PC/Documents/PythonPrograms/currencyconverter.py", line 70
    + "&to_currency=" toCur + "&apikey=" + apiKey

I ran all the other functions and they check out. 

您在第69行的&to_currency=和toCur之间缺少一个+符号,假设您提供了此文件中的所有源代码

# return requests 
inputURL = baseURL + "&from_currency=" + fromCur\
           + "&to_currency=" + toCur + "&apikey=" + apiKey

您的应用程序在字符串浓度方面有问题

import urllib

# Python 3:
import urllib.parse

getVars = {'function': 'CURRENCY_EXCHANGE_RATE', 'from_currency': 'fromCur', 'to_currency': toCur, 'apiKey': apiKey}
url = "http://www.alphavantage.co/query?"

# Python 2:
inputURL = url + urllib.urlencode(getVars)

# Python 3:
inputURL = url + urllib.parse.urlencode(getVars)
或使用格式


是否可以让问题更具描述性的标题,如描述问题,而不是问题的上下文?为什么这个标记的C++?如果你读错误信息中给出的代码行,你应该看到它缺少一个+符号。我希望ApIKEY不是你的。不管怎样,正如赫尔伍德所说,将inputURL=baseURL+&从\u currency=+fromCur+&更改为\u currency=toCur+&apikey=+apikey=+inputURL=baseURL+&从\u currency=+fromCur+&更改为\u currency=+toCur+&apikey=+apikey我已经修复了第70行,但第83行文件C:/Users/Pig Toy的PC/Documents/PythonPrograms/currencyconverter.py出现了另一个错误,第83行CalculateMT=RoundInputMT*exchangeRate,2@TheCodeOfDHT您在第79行['5,汇率']
inputURL = "{}&to_currency={}&apiKey={}".format(baseURL, toCur, apiKey)