如何检查字符串是否只包含数字?
我已经在这里试了一下.我想看看实现这一目标的最简单方法.
import string
def main():
isbn = input("Enter your 10 digit ISBN number: ")
if len(isbn) == 10 and string.digits == True:
print ("Works")
else:
print("Error, 10 digit number was not inputted and/or letters were inputted.")
main()
if __name__ == "__main__":
main()
input("Press enter to exit: ")
Run Code Online (Sandbox Code Playgroud) 如何在python中删除CSV文件的第一行,我的CSV文件的前几行是:
Domain Name, ItemID, Auction Type, Time Left, Price, Bids, Domain Age, Traffic,ValuationPrice
TICKETFINE.COM,134774365,Bid,05/09/2014 08:00 AM (PDT),$100,0,0,0,$0
CREATINGMY.COM,134774390,Bid,05/09/2014 08:00 AM (PDT),$500,0,0,0,$0
WPTHEMEHELP.COM,134774444,Bid,05/09/2014 08:00 AM (PDT),$45,1,0,0,$0
APK-ZIPPY.COM,134774445,Bid,05/09/2014 08:00 AM (PDT),$10,0,0,0,$0
FAMILYBUZZMARKETING.COM,134689583,Bid,05/09/2014 08:00 AM (PDT),$90,0,0,0,$0
AMISRAGAS.COM,134689584,Bid,05/09/2014 08:00 AM (PDT),$35,0,0,0,$0
Run Code Online (Sandbox Code Playgroud) 如何在sqlite3查询中添加多个WHERE子句,例如:
c.execute("SELECT * FROM requests WHERE driverID=? AND WHERE accepted='False'", (str(sid_login.get()),))
Run Code Online (Sandbox Code Playgroud)
虽然我收到“在“ WHERE”附近:语法错误”错误。
我在分割字符串时遇到问题,它一直说option_convert和option_convert3不等于美元和英镑
代码:http://pastebin.com/HFSW2BU2
由于某种原因无法在这里工作.
def option1():
option_convert = input("""
What curreny would you you like to convert and convert to, (Example: dollar & pound) this would allow you to convert dollars to pounds.
""")
option_convert2 = option_convert.split('&')[0]
option_convert3 = option_convert.split('&')[1]
print (option_convert2)
print (option_convert3)
if option_convert2 == "dollar" and option_convert3 == "pound":
print ("test")
else:
print("Something went wrong...")
Run Code Online (Sandbox Code Playgroud) 例如,如何使字符串重复自身:
而不是写print ('---------------------------')我怎么做它的东西print ('-') * 60?
我有这个列表的问题,我想将每个数字乘以一定的数字,但目前列表中的每个数据都是一个字符串,如果我将列表转换为整数或将字符串转换为整数把它变成一个列表,我收到一个错误.
def main():
isbn = input("Enter you're 10 digit ISBN number: ")
if len(isbn) == 10 and isbn.isdigit():
list_isbn = list(isbn)
print (list_isbn)
print (list_isbn[0] * 2)
else:
print("Error, 10 digit number was not inputted and/or letters were inputted.")
main()
if __name__ == "__main__":
main()
input("Press enter to exit: ")
Run Code Online (Sandbox Code Playgroud) 我正在使用Python3,当我们按下登录按钮时,我试图将用户在用户名和密码框中键入的内容传递给登录功能.登录功能只需将用户名标签打包到GUI上即可.
码:
import tkinter
from tkinter import *
import sys
def login_gui():
global login_window
global studentid_entry_login
usr_login = StringVar()
pwd_login = StringVar()
login_window=tkinter.Tk()
login_window.title("Login")
login_window.geometry("200x200+500+300")
username_label_login = tkinter.Label(login_window, text="Username:").pack()
username_entry_login = tkinter.Entry(login_window, textvariable=usr_login).pack()
password_label_login = tkinter.Label(login_window, text="\nPassword:").pack()
password_entry_login = tkinter.Entry(login_window, textvariable=pwd_login).pack()
button_login = tkinter.Button(login_window, text="Login", command = login).pack()
login_window.mainloop()
def login():
username = usr_login.get()
label1 = tkinter.Label(login_window, text=username).pack()
return
login_gui()
Run Code Online (Sandbox Code Playgroud)
追溯:
Traceback (most recent call last):
File "C:/Python33/Folder/tkinter-test.py", line 25, in <module>
login_gui()
File "C:/Python33/Folder/tkinter-test.py", line 8, in login_gui
usr_login …Run Code Online (Sandbox Code Playgroud)