我正在努力在python中创建一个需要的菜单:
我是Python的新手,我无法弄清楚我在代码中做错了什么.
到目前为止这是我的代码:
ans=True
while ans:
print (""""
1.Add a Student
2.Delete a Student
3.Look Up Student Record
4.Exit/Quit
"""")
ans=input("What would you like to do?"
if ans=="1":
print("\nStudent Added")
elif ans=="2":
print("\n Student Deleted")
elif ans=="3":
print("\n Student Record Found")
elif ans=="4":
print("\n Goodbye")
elif ans !="":
print("\n Not Valid Choice Try again")
Run Code Online (Sandbox Code Playgroud)
ANSWERED
这显然是他想要的:
menu = {}
menu['1']="Add Student."
menu['2']="Delete Student."
menu['3']="Find Student"
menu['4']="Exit"
while True:
options=menu.keys()
options.sort()
for entry in options: …Run Code Online (Sandbox Code Playgroud) 我正在使用OS X Mavericks和zsh(技术上是包哦oh-my-zsh).
我已经有一段时间以来一直面对这个bug,并且还没有办法解决它.有时当我管道命令它只是说找不到命令.
例如,当我执行nmap网络列表扫描时,nmap -sL 192.168.2.0/24 | grep ')'我有时会收到错误zsh: command not found: grep.即使我使用向上箭头按钮它也不起作用,所以我必须重写命令,完全一样,它会起作用.
它真的很烦人,它偶尔发生在其他命令上,主要是在管道之后.
知道为什么会这样吗?
在使用Subversion管理的项目中使用Autoconf时,我会将此代码放入:configure.ac
AC_REVISION($Revision: 1234 $)
Run Code Online (Sandbox Code Playgroud)
使用svn:keywords Revision,AC_REVISION会将修订号configure.ac插入生成的configure脚本中.
如何在使用Git管理的项目中做类似的事情?
Git没有像这样的关键字$Revision$,也没有这样的修订号.但它确实有提交的SHA1,和git describe.我只是不确定如何将其纳入其中configure.ac.
我的子查询给出了一个错误: Msg 102, Level 15, State 1, Line 17 Incorrect syntax near ')'.
SELECT SalesArea, Branch, Volume
from
(select
br.SalesArea as SalesArea
,br.Branch as Branch
, sum(a.Volume) as Volume
FROM dbo.vDetail a with (nolock)
LEFT JOIN
dbo.vBranch AS br WITH (nolock)
ON a.Branch = br.Branch
group by a.Volume, br.SalesArea, br.Branch)
Run Code Online (Sandbox Code Playgroud) 在wpf中创建app.config(c#)
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear />
<add name="Name"
providerName="MySql.Data"
connectionString="Server=.net;Uid=;Pwd=H;Database=;charset=utf8;Allow Zero Datetime=true;" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
用过的代码C#:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringsSection conStr = config.ConnectionStrings;
if (!conStr.SectionInformation.IsProtected)
{
conStr.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
conStr.SectionInformation.ForceSave = true;
config.Save();
}
else
{
foreach (ConnectionStringSettings ss in conStr.ConnectionStrings)
Console.WriteLine(ss);
Console.Read();
}
Run Code Online (Sandbox Code Playgroud)
config.Save(); - 导致异常:
{"无法使用提供程序'RsaProtectedConfigurationProvider'加密'connectionStrings'部分.来自提供程序的错误消息:对象已存在.\ r \n"}}
我正在阅读源代码xl2tpd,并在阅读此代码时遇到很多问题.例如,我无法找到结构lac的定义位置.我如何找到这个结构的定义?
我使用ctags和vim来读取此代码,但未能找到结构.我用Google搜索,找不到结构.有没有什么方法可以让代码阅读过程更舒服?也就是说,我可以跳到大多数变量,函数和结构的定义?
我做了一个"游戏".我喜欢玩它,我想将它分发给我的朋友,而无需在他们的计算机上安装Python和Pygame.
我对Py2Exe和Pyinstaller做了很多研究.我查看了许多教程,修复,错误,但它们似乎都没有帮助我.
Pyinstaller没用,因为它不喜欢Pygame中的字体,Py2exe也不会编译内置模块,所以我发现Pygame2exe只是一个预制的安装脚本,用于py2exe,包括pygame和fonts.它应该构建良好,但exe无法使用...我收到错误:
"Microsoft Visual C++运行时库
运行时错误!
程序C:...\dist\Worm Game.exe
此应用程序已请求Runtime以不寻常的方式终止.有关更多信息,请联系应用程序的支持团队."
我只是不明白......为什么我不能编译这个游戏!
这是用Python 2.7制作的游戏代码:
import pygame
import random
import os
pygame.init()
class Worm:
def __init__(self, surface):
self.surface = surface
self.x = surface.get_width() / 2
self.y = surface.get_height() / 2
self.length = 1
self.grow_to = 50
self.vx = 0
self.vy = -1
self.body = []
self.crashed = False
self.color = 255, 255, 0
def event(self, event):
if event.key == pygame.K_UP:
if self.vy != 1:
self.vx = 0
self.vy = -1
else:
a …Run Code Online (Sandbox Code Playgroud) 我有一个表示基于JSON的API的类层次结构.有一个通用工厂使用.NET 4(没有第三方库)将api调用和反序列化为类.我试图避免必须实例化该类来检索每个类唯一的只读信息.
我曾经想过(直到我开始阅读这篇文章,然后 ......)我会将静态URL与基类/接口相关联,然后在派生类的构造函数中设置它.像(这个例子不起作用):
abstract class url {
public abstract static string URL; // This is invalid syntax!
}
class b : url {
static b () { URL = "http://www.example.com/api/x/?y=1"; }
}
class c: url {
static c () { URL = "http://www.example.com/api/z"; }
}
// ... so the factory can do something like ...
b result = doJSONRequest<b>(b.URL);
Run Code Online (Sandbox Code Playgroud)
这不起作用.静态字段不能是抽象的,也不能在b 和 c中唯一设置,因为静态变量存储在它定义的类中(在本例中为url).
如何才能有一个与类关联的只读项,以便您可以访问该项(等)而无需实例化该类?
我遗漏了一些基本的东西,但我无法理解.鉴于:
abstract class EventBase {}
class SpecialEvent : EventBase {}
Run Code Online (Sandbox Code Playgroud)
在另一个课程中,我希望允许呼叫者能够 RegisterFor<SpecialEvent>(x => {...})
public class FooHandler {
{
internal Dictionary<Type, Action<EventBase>> _validTypes = new Dictionary<Type, Action<EventBase>>();
internal void RegisterFor<T>(Action<T> handlerFcn) where T: EventBase
{
_validTypes.Add(typeof(T), handlerFcn);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,该_validTypes.Add行无法编译.它无法将a转换Action<T>为Action<EventBase>.约束指定T必须从中派生出来EventBase,所以我误解了什么?