所以,如果我有一个班级:
class Person(object):
'''A class with several methods that revolve around a person's Name and Age.'''
def __init__(self, name = 'Jane Doe', year = 2012):
'''The default constructor for the Person class.'''
self.n = name
self.y = year
Run Code Online (Sandbox Code Playgroud)
然后这个子类:
class Instructor(Person):
'''A subclass of the Person class, overloads the constructor with a new parameter.'''
def __init__(self, name, year, degree):
Person.__init__(self, name, year)
Run Code Online (Sandbox Code Playgroud)
我有点迷失了如何让子类调用并使用父类构造函数,name并在子类中year添加新参数degree.
好的,我的问题是:
我有一个表itemconfig,其中有很多关于存储在我们仓库中的项目的数据.我需要选择一个特殊group的项目,这样我就可以做一些与工作相关的测试.到目前为止,当我滚动浏览数据库时,我一直在脑子里做数学,但必须有一个更简单的方法.
在itemconfig中我想特别查看列case_qty和pal_qty以及itm_num.我想要做的是选择所有itm_num,其中pal_qty / case_qty大于say 500.这将itm_num立即给我所有与我的测试相关的信息.可悲的是,我不熟悉如何做到这一点,或者甚至可能.
谢谢.
所以我试着通过查看这里的程序集来编写一些C代码:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
addl 8(%ebp), %eax
movzbl (%eax), %eax
movsbl %al,%eax
popl %ebp
ret
Run Code Online (Sandbox Code Playgroud)
我看到我有两个变量,它们被加在一起,然后当看到函数开始调用movzbl和movesbl时我迷路了.这里发生了什么?
好吧基本上我写了一个不太漂亮的GUI,提供随机简单的数学问题.它就像我想要的那样工作.然而,每次我点击进入时,闲置的Shell会向我吐出红色.尽管如此,就像我说的那样,它继续按照我的意愿运作.所以我无法理解为什么我的代码的这个特定部分会导致问题.为长段代码道歉:
from tkinter import Label, Frame, Entry, Button, LEFT, RIGHT, END
from tkinter.messagebox import showinfo
import random
class Ed(Frame):
'Simple arithmetic education app'
def __init__(self,parent=None):
'constructor'
Frame.__init__(self, parent)
self.pack()
self.tries = 0
Ed.make_widgets(self)
Ed.new_problem(self)
def make_widgets(self):
'defines Ed widgets'
self.entry1 = Entry(self, width=20, bg="gray", fg ="black")
self.entry1.grid(row=0, column=0, columnspan=4)
self.entry1.pack(side = LEFT)
self.entry2 = Entry(self, width=20, bg="gray", fg ="black")
self.entry2.grid(row=2, column=2, columnspan=4)
self.entry2.pack(side = LEFT)
Button(self,text="ENTER", command=self.evaluate).pack(side = RIGHT)
def new_problem(self):
'creates new arithmetic problem'
opList = ["+", "-"]
a …Run Code Online (Sandbox Code Playgroud) 我知道递归是一个函数调用自身的时候,但我无法弄清楚如何让我的函数自我调用以获得所需的结果.我需要简单地计算给函数的字符串中的元音.
def recVowelCount(s):
'return the number of vowels in s using a recursive computation'
vowelcount = 0
vowels = "aEiou".lower()
if s[0] in vowels:
vowelcount += 1
else:
???
Run Code Online (Sandbox Code Playgroud)
最后我想出了这个,感谢这里的一些见解.
def recVowelCount(s):
'return the number of vowels in s using a recursive computation'
vowels = "aeiouAEIOU"
if s == "":
return 0
elif s[0] in vowels:
return 1 + recVowelCount(s[1:])
else:
return 0 + recVowelCount(s[1:])
Run Code Online (Sandbox Code Playgroud) 我正在处理一个组项目,我们需要在我们正在处理的图表中创建一个特定节点属性的所有值的列表.每个节点有6个属性,我们只需要列出其中一个属性的所有值.
import networkx as nx
import scipy as sp
import matplotlib.pyplot as plt
%matplotlib inline
import urllib
url = "http://josquin.cti.depaul.edu/~rburke/courses/s14/fmh.graphml"
sock = urllib.urlopen(url) # open URL
fmh = nx.read_graphml(sock)
for i in fmh:
if fmh.node[i]['Race'] == 'Asian':
fmh.add_node(i, RaceN=0)
elif fmh.node[i]['Race'] == 'Black':
fmh.add_node(i, RaceN=1)
elif fmh.node[i]['Race'] == 'Hisp':
fmh.add_node(i, RaceN=2)
elif fmh.node[i]['Race'] == 'NatAm':
fmh.add_node(i, RaceN=3)
elif fmh.node[i]['Race'] == 'Other':
fmh.add_node(i, RaceN=4)
elif fmh.node[i]['Race'] == 'White':
fmh.add_node(i, RaceN=5)
for i in fmh:
if fmh.node[i]['Sex'] == 'F':
fmh.add_node(i, SexN=0)
elif …Run Code Online (Sandbox Code Playgroud) 我不知道如何保持这个简单......我希望有人看看我的代码然后告诉我为什么我的功能不能正常工作......
我有一节课:
class PriorityQueue(object):
'''A class that contains several methods dealing with queues.'''
def __init__(self):
'''The default constructor for the PriorityQueue class, an empty list.'''
self.q = []
def insert(self, number):
'''Inserts a number into the queue, and then sorts the queue to ensure that the number is in the proper position in the queue.'''
self.q.append(number)
self.q.sort()
def minimum(self):
'''Returns the minimum number currently in the queue.'''
return min(self.q)
def removeMin(self):
'''Removes and returns the minimum number from the queue.''' …Run Code Online (Sandbox Code Playgroud) 好的,这是我的代码:
#include <stdio.h>
void convert_weight(int x , char a, int* y, char* b)
{
if (a == 'F')
*y = (x-32) * 5 / 9;
*b = 'C';
if(a == 'C')
*y = x*9 / 5 + 32;
*b = 'F';
}
int main()
{
int degrees1 = 50, degrees2;
char scale1 = 'F', scale2;
convert_weight(degrees1, scale1, °rees2, &scale2);
printf("%d %c = %d %c\n", degrees1, scale1, degrees2, scale2);
degrees1 = 10;
scale1 = 'C';
convert_weight(degrees1, scale1, °rees2, &scale2);
printf("%d %c …Run Code Online (Sandbox Code Playgroud)