我是python的新手,如果这有点基础,请抱歉。
我进行了轮盘游戏,以提高我的编程技能,并且遇到了一个非常奇怪的错误。首先,当我想在下注结束时打印玩家的余额时,一旦检查了结果,它就打印出包含所有红色数字的数组。我查看了定义balance
变量的代码,但似乎没有什么可能影响它。
我出于某种原因认为将balance
定义为int(100)
而不是100
可以解决此问题,但是却出现了以下错误:TypeError: checkresults() missing 1 required positional argument: 'bet'
我在{中删除了int
{1}},并且仍然存在。对于那些想知道的人,我使balance
使用checkresults
,甚至尝试将其移动到使用的变量列表中的位置,但仍然没有解决方法。如您所见,bet
是它使用的第一个变量。 balance = checkresults(bet, bet_choice, number, balance, red, black, green, first, second, third)
的完整代码在这里:
checkresults
下注值由以下决定:
def checkresults(self, bet_choice, number, balance, red, black, green, first, second, third, bet):
if bet_choice == "number":
if bet == number:
balance = balance + (bet_amount*14)
print("You Won!")
else:
print("You Lost")
elif bet_choice == "colour":
if bet == "red":
if number in red:
balance = balance + (bet_amount*2)
print("You Won!")
else:
print("You Lost")
elif bet == "black":
if number in black:
balance = balance + (bet_amount*2)
print("You Won!")
else:
print("You Lost")
else:
if number in green:
balance = balance + (bet_amount*14)
print("You Won!")
else:
print("You Lost")
elif bet_choice == "third":
if bet == "1st":
if number in first:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
elif bet == "2nd":
if number in second:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
elif bet == "3rd":
if number in third:
balance = balance + (bet_amount*3)
print("You Won!")
else:
print("You Lost")
return balance
答案 0 :(得分:0)
由于先前的错误,我在Tab1Page_Host.ngfactory.js? [sm]:1 ERROR ReferenceError: Parser is not defined
at new Tab1Page (tab1.page.ts:20)
at createClass (core.js:22142)
at createDirectiveInstance (core.js:22019)
at createViewNodes (core.js:23245)
at createRootView (core.js:23159)
at callWithDebugContext (core.js:24167)
at Object.debugCreateRootView [as createRootView] (core.js:23677)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:21498)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create (core.js:9934)
at ViewContainerRef_.push../node_modules/@angular/core/fesm5/core.js.ViewContainerRef_.createComponent (core.js:21609)
View_Tab1Page_Host_0 @ Tab1Page_Host.ngfactory.js? [sm]:1
proxyClass @ compiler.js:18234
push../node_modules/@angular/core/fesm5/core.js.DebugContext_.logError @ core.js:24129
push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:15762
(anonymous) @ core.js:18116
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:17248
push../node_modules/@angular/core/fesm5/core.js.ApplicationRef.tick @ core.js:18116
(anonymous) @ core.js:18000
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
onInvoke @ core.js:17289
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:390
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
push../node_modules/@angular/core/fesm5/core.js.NgZone.run @ core.js:17203
next @ core.js:18000
schedulerFn @ core.js:13505
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:196
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:134
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:77
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:54
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:13489
checkStable @ core.js:17258
onHasTask @ core.js:17302
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.hasTask @ zone.js:443
push../node_modules/zone.js/dist/zone.js.ZoneDelegate._updateTaskCount @ zone.js:463
push../node_modules/zone.js/dist/zone.js.Zone._updateTaskCount @ zone.js:291
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:212
drainMicroTaskQueue @ zone.js:601
Promise.then (async)
scheduleMicroTask @ zone.js:584
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:413
onScheduleTask @ zone.js:301
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:404
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:238
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:258
scheduleResolveOrReject @ zone.js:879
resolvePromise @ zone.js:825
(anonymous) @ zone.js:741
webpackJsonpCallback @ bootstrap:25
(anonymous) @ tab1-tab1-module.js:1
Tab1Page_Host.ngfactory.js? [sm]:1 ERROR CONTEXT DebugContext_ {view: {…}, nodeIndex: 1, nodeDef: {…}, elDef: {…}, elView: {…}}
View_Tab1Page_Host_0 @ Tab1Page_Host.ngfactory.js? [sm]:1
proxyClass @ compiler.js:18234
push../node_modules/@angular/core/fesm5/core.js.DebugContext_.logError @ core.js:24129
push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:15767
(anonymous) @ core.js:18116
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:17248
push../node_modules/@angular/core/fesm5/core.js.ApplicationRef.tick @ core.js:18116
(anonymous) @ core.js:18000
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
onInvoke @ core.js:17289
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:390
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
push../node_modules/@angular/core/fesm5/core.js.NgZone.run @ core.js:17203
next @ core.js:18000
schedulerFn @ core.js:13505
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:196
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:134
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:77
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:54
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:13489
checkStable @ core.js:17258
onHasTask @ core.js:17302
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.hasTask @ zone.js:443
push../node_modules/zone.js/dist/zone.js.ZoneDelegate._updateTaskCount @ zone.js:463
push../node_modules/zone.js/dist/zone.js.Zone._updateTaskCount @ zone.js:291
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:212
drainMicroTaskQueue @ zone.js:601
Promise.then (async)
scheduleMicroTask @ zone.js:584
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:413
onScheduleTask @ zone.js:301
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:404
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:238
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:258
scheduleResolveOrReject @ zone.js:879
resolvePromise @ zone.js:825
(anonymous) @ zone.js:741
webpackJsonpCallback @ bootstrap:25
(anonymous) @ tab1-tab1-module.js:1
core.js:15714 ERROR Error: Uncaught (in promise): ReferenceError: Parser is not defined
ReferenceError: Parser is not defined
at new Tab1Page (tab1.page.ts:20)
at createClass (core.js:22142)
at createDirectiveInstance (core.js:22019)
at createViewNodes (core.js:23245)
at createRootView (core.js:23159)
at callWithDebugContext (core.js:24167)
at Object.debugCreateRootView [as createRootView] (core.js:23677)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:21498)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create (core.js:9934)
at ViewContainerRef_.push../node_modules/@angular/core/fesm5/core.js.ViewContainerRef_.createComponent (core.js:21609)
at resolvePromise (zone.js:831)
at resolvePromise (zone.js:788)
at zone.js:892
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:17280)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)
代码的定义部分有self
。我删除了checkresults
和1:它修复了新错误,而2:旧错误没有恢复。
答案 1 :(得分:0)
checkresults
包含11个参数-看起来第一个参数应该是checkresults
在 in 中定义的类的实例-当您调用方法直接引用而不引用实例 it ,它认为您没有传递第11个参数。
答案 2 :(得分:-1)
我正在做完全相同的事情。我大约两个半月前开始使用python,在过去的一个月里一直在从事轮盘游戏。
这不能回答问题,但是开始时我遇到了类似的问题。如果您打算建立整个游戏,那么您走的路就不可持续。 elif语句太多,您将想要撕开头发(就像我一样)。
我最终要做的是将所有“常量”放入字典中。通过常数,我指的是每个投注中的数字(红色与黑色,奇数与偶数等),方向盘上的数字以及每个投注的支出。
从那里,您可以使用字典方法来查找下注词典中的中奖号码(即,这是一个红色还是黑色的数字),然后将其与下注字典进行比较,如果有匹配项,请查找下注的支出。
祝你好运!