python-3.3

Shuffle a python list without using the built-in function

陌路散爱 提交于 2019-12-30 12:16:30
问题 I'm working on writing two different shuffle functions. The first shuffle function must take a list and return a new list with the elements shuffled into a random order. This is what I have so far for the first shuffle function- def shuf(List): import random newList=[] for i in List: i=random.randrange(len(List)) newList+=i return newList The second shuffle function takes a list as a parameter and shuffles the list in place. I know how to do it with the built-in function but I'm not allowed

Shuffle a python list without using the built-in function

て烟熏妆下的殇ゞ 提交于 2019-12-30 12:15:11
问题 I'm working on writing two different shuffle functions. The first shuffle function must take a list and return a new list with the elements shuffled into a random order. This is what I have so far for the first shuffle function- def shuf(List): import random newList=[] for i in List: i=random.randrange(len(List)) newList+=i return newList The second shuffle function takes a list as a parameter and shuffles the list in place. I know how to do it with the built-in function but I'm not allowed

Using the crypt module in Windows?

坚强是说给别人听的谎言 提交于 2019-12-29 08:48:13
问题 In IDLE and Python version 3.3.2, I try and call the python module like so: hash2 = crypt(word, salt) I import it at the top of my program like so: from crypt import * The result I get is the following: Traceback (most recent call last): File "C:\none\of\your\business\adams.py", line 10, in <module> from crypt import * File "C:\Python33\lib\crypt.py", line 3, in <module> import _crypt ImportError: No module named '_crypt' However, when I execute the same file adams.py in Ubuntu, with Python 2

Matplotlib Basemap animation

穿精又带淫゛_ 提交于 2019-12-29 07:16:08
问题 I'm using basemap to plot some points on a map, and I want to add any kind of animation to it. It could literally serve no purpose at all, as long as it is an animation it would be nice. This is what I currently have to make the map, from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np import matplotlib.animation as animation map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map

Pygame attribute, init()

↘锁芯ラ 提交于 2019-12-29 01:49:06
问题 I'm trying to use Pygame with Python 3.3 on my windows 8 laptop. Pygame installed fine and when I import pygame it imports fine as well. Although when I try to execute this small code: import pygame pygame.init() size=[700,500] screen=pygame.display.set_mode(size) I get this error: Traceback (most recent call last): File "C:\Users\name\documents\python\pygame_example.py", line 3, in <module> pygame.init() AttributeError: 'module' object has no attribute 'init' I used pygame-1.9.2a0-hg

Python float to ratio

风流意气都作罢 提交于 2019-12-28 16:03:49
问题 I try get ration of variable and get unexpected result. Can somebody explain this? >>> value = 3.2 >>> ratios = value.as_integer_ratio() >>> ratios (3602879701896397, 1125899906842624) >>> ratios[0] / ratios[1] 3.2 I using python 3.3 But I think that (16, 5) is much better solution And why it correct for 2.5 >>> value = 2.5 >>> value.as_integer_ratio() (5, 2) 回答1: Use the fractions module to simplify fractions: >>> from fractions import Fraction >>> Fraction(3.2) Fraction(3602879701896397,

Algorithm for finding if an array is balanced [closed]

元气小坏坏 提交于 2019-12-25 18:56:30
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I'm trying to create a program that will create a 10 element array and then assign random values to each element. I then want the program to tell if the

fill out a webform that uses javascript with python

两盒软妹~` 提交于 2019-12-25 18:19:42
问题 i am trying to fill out a webform using a python program by submitting specific values. the problem is it uses javascript. i will post an example of the value i want to fill. fo.addVariable("email","email@yahoo.com") fo.addVariable("age","19") fo.addVariable("gender","M") fo.addVariable("line","hello") that is an example of the value on the page. what i want to do is submit a value to that and change it. what i am currently attempting is this: data = urllib.parse.urlencode({"line": "hello",

Button Icon Change on Click

一曲冷凌霜 提交于 2019-12-25 16:54:07
问题 I'm trying to make a GUI Application that change the icon on the right clicked button! This is my simple code: import sys from PySide.QtCore import * from PySide.QtGui import * class Ui_MainWindow(QMainWindow): def __init__(self): super().__init__() self.setupUi() def setupUi(self): widget = QWidget() layout = QGridLayout() self.buttons = list() for x in range(3): row = list() for y in range(3): button = QPushButton(QIcon('Empty-Cell.png'), '{},{}'.format(x, y)) button.clicked.connect(self

AttributeError: 'NoneType' object has no attribute 'write'

╄→гoц情女王★ 提交于 2019-12-25 10:56:10
问题 I am trying to run a game me and my friends made in python... It was sent to me by e-mail. i know i have a newer version of python but im not sure if that is the problem. This is the function we defined: def text(x,y,text,size): turtle.penup() turtle.goto(x,y) turtle.pendown() turtle.write(text,font=('Arial',size,'normal')) we call it here: def home_screen(): turtle.bgpic("bgarmy.gif") turtle.fillcolor("#46B347") turtle.fill(True) rectangle(-150,100,300,100) turtle.fill(False) text(-70,130,