初学者程序员在这里.所以忍受我.我有一个简单的python程序.
print "How tall are you?",
height = raw_input()
print "So you're %r tall" %(height)
Run Code Online (Sandbox Code Playgroud)
如果我输入高度为6'6''将输出python
所以你是'6\6"'
如何从输出中删除正斜杠"\"?
提前致谢!
我知道在使用时argv
我必须输入文件作为参数(例如:)python ex15.py ex15_sample.txt
,使用时raw_input
我输入文件名作为输入.
但我似乎无法找出为什么获取文件名的方法会比另一种更好.有人可以解释原因吗?
我正在尝试制作密码强度测试仪.密码需要至少有4个数字和6个字母,所以我需要找出用户输入的数量raw_input
.
想知道是否有更好的方法来做到这一点.Python是我的第一个编程语言.
while True:
amount_per_month = raw_input('\nWhat is the monthly cost?\n==> ')
# seperate dollars and cents.
amount_list = amount_per_month.split(".")
# checking if int(str) is digit
if len(amount_list) == 1 and amount_list[0].isdigit() == True:
break
# checking if float(str) is digit
elif len(amount_list) == 2 and amount_list[0].isdigit() and amount_list[1].isdigit() == True:
break
else:
raw_input('Only enter digits 0 - 9. Press Enter to try again.')
continue
Run Code Online (Sandbox Code Playgroud) 这是一个非常基本的问题,我遇到了麻烦.我有一个python程序,当我raw_input
用来获取用户输入时,每当我尝试删除用户已经输入的内容时,会出现这个符号:^H
而不是允许我删除我已输入的内容.如何允许用户删除他们键入的先前内容?
我决定修改以下while循环并在函数内使用它,以便循环可以取任何值而不是6.
i = 0
numbers = []
while i < 6:
numbers.append(i)
i += 1
Run Code Online (Sandbox Code Playgroud)
我创建了以下脚本,以便我可以使用变量(或更具体的参数)而不是6.
def numbers(limit):
i = 0
numbers = []
while i < limit:
numbers.append(i)
i = i + 1
print numbers
user_limit = raw_input("Give me a limit ")
numbers(user_limit)
Run Code Online (Sandbox Code Playgroud)
当我没有使用它raw_input()
并简单地从脚本中放入参数它工作正常但现在当我运行它(在Microsoft Powershell中)时,在询问问题后光标会不断闪烁raw_input()
.然后我必须按CTRL+ C才能中止它.也许这个功能不会被调用raw_input()
.
现在它给出了像pic中的内存错误.
我编程初学者为iPython编写一个简单的控制台闪卡程序来学习德语单词.答案密钥是一个excel文件,我将其读入,组织并保存为unicode字符串.当用户需要向控制台输入德语单词时,会出现此问题.
我在顶部有这个:
# -*- coding: utf-8 -*-
Run Code Online (Sandbox Code Playgroud)
然后我读入(通过键入控制台)德语单词Kaufhäuser
var = raw_input().decode('utf-8')
Run Code Online (Sandbox Code Playgroud)
然后,只要我在控制台中输入它,我就会收到以下错误:
UnicodeDecodeError: 'utf8' codec can't decode byte 0x84 in position 5:
invalid start byte
Run Code Online (Sandbox Code Playgroud)
Stack Overflow上处理变音符号的其他解决方案似乎指向第一行代码,或解码字符串以将其转换为unicode.但在每种情况下,用户都将字符串输入到代码而不是使用raw_input()读取它,并且我总是收到错误消息.
我正在创建一个用户可以使用的财务建模工具.我希望用户能够通过键入变量名来输入他们想要使用的方法.但是,使用我的代码,raw_input只是给出了一个他们输入的字符串,而不是变量名本身
loose = 5
accurate = 10
extreme = 15
method = raw_input('Would you like the calculation to be loose, accurate, or extreme in its precision?: ") #the user would either type loose, accurate, or extreme
calculation = x*y*method #x and y is just a generic calculation and method should be equal to either 5, 10, or 15 based on whether the user chose loose, accurate, or extreme
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,说方法不是int.我能做些什么来使它等于上面的松散,准确或极端值?
是否可以将多个换行符输入到多个变量中int
并一次声明它们?
为了进一步解释我要完成的工作,我知道这是我们如何使用map进行空格分隔的输入:
>>> a, b = map(int, input().split())
3 5
>>> a
3
>>> b
5
Run Code Online (Sandbox Code Playgroud)
有换行符吗?就像是:
a, b = map(int, input().split("\n"))
改写:我试图一次从多行中获取多个整数输入。
我有一个应用程序使用原始输入做一些复杂的事情,我想有一些自动化测试.这是发送输入的代码,虽然有点切碎,以便更容易理解.
发送:
GetRawInputDeviceList(nullptr, &numDevices, sizeof(RAWINPUTDEVICELIST));
rawInputDeviceList = new RAWINPUTDEVICELIST[numDevices];
GetRawInputDeviceList(rawInputDeviceList, &numDevices, sizeof(RAWINPUTDEVICELIST));
HGLOBAL hRaw = ::GlobalAlloc(GHND, sizeof(RAWINPUT));
RAWINPUT *pRaw = reinterpret_cast<RAWINPUT*>(::GlobalLock(hRaw));
pRaw->data.keyboard.MakeCode = 30;
pRaw->data.keyboard.Flags = 0;
pRaw->data.keyboard.Reserved = 0;
pRaw->data.keyboard.VKey = 0x43;
pRaw->data.keyboard.Message = WM_KEYDOWN;
pRaw->data.keyboard.ExtraInformation = 0;
pRaw->header.dwType = RIM_TYPEKEYBOARD;
pRaw->header.dwSize = sizeof(RAWINPUT);
pRaw->header.hDevice = rawInputDeviceList[0].hDevice;
pRaw->header.wParam = (WPARAM)RIM_INPUT;
::GlobalUnlock(hRaw);
SendMessage(hWnd_, WM_INPUT, (WPARAM)RIM_INPUT, (LPARAM)hRaw);
Run Code Online (Sandbox Code Playgroud)
接收:
case WM_INPUT:
UINT size = 0;
if(GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)))
return GetLastError();
Run Code Online (Sandbox Code Playgroud)
GetLastError()的返回值是ERROR_INVALID_HANDLE(6).但是,如果我自己使用GlobalLock,我可以读取句柄.
根据http://msdn.microsoft.com/en-us/library/windows/desktop/ms645596(v=vs.85).aspx"lParam:RAWINPUT 结构的句柄.这来自WM_INPUT中的lParam. "
我试过只使用指针,我得到相同的错误信息.我已尝试使用/不使用解锁,以及使用LocalAlloc/LocalLock.我已经尝试过使用PostMessage而且结果完全相同,而且我现在已经没想到了.
raw-input ×10
python ×9
input ×2
argv ×1
c++ ×1
diacritics ×1
forward ×1
python-2.7 ×1
python-3.x ×1
slash ×1
string ×1
unicode ×1
while-loop ×1
windows ×1