因此,目前正在学习如何导入数据并在matplotlib中使用它,我甚至遇到了麻烦,即使我从本书中获得了确切的代码.
这是情节的样子,但我的问题是如何在x轴的开始和结束之间没有空白的地方得到它.
这是代码:
import csv
from matplotlib import pyplot as plt
from datetime import datetime
# Get dates and high temperatures from file.
filename = 'sitka_weather_07-2014.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
#for index, column_header in enumerate(header_row):
#print(index, column_header)
dates, highs = [], []
for row in reader:
current_date = datetime.strptime(row[0], "%Y-%m-%d")
dates.append(current_date)
high = int(row[1])
highs.append(high)
# Plot data.
fig = plt.figure(dpi=128, figsize=(10,6))
plt.plot(dates, highs, c='red')
# Format plot.
plt.title("Daily high temperatures, July 2014", fontsize=24) …Run Code Online (Sandbox Code Playgroud) 我试图判断并分割该句子,将其翻转,并将其打印到屏幕上.
我无法理解它是如何.reverse()工作的?当我做的事情:
test = ['This','is','a','test']
new_test = test.reverse()
print(new_test)
Run Code Online (Sandbox Code Playgroud)
当我跑这个我得到None,为什么这个?我怎样才能.reverse()上班?
这是我的最终代码:
sentence = input("What is your sentence? ")
split_sentence = sentence.split().reverse()
for word in sentence:
print(word,end='')
Run Code Online (Sandbox Code Playgroud) 我正在通过麻省理工学院开放式课程介绍计算机编程课程,我不确定我是否正确地解决了简单的模拟问题.
- Yahtzee的概率是多少啊!在第一卷?也就是说,滚动五个6面骰子的概率是多少,并且它们都显示相同的数字?
- 编写蒙特卡罗模拟来解决上述问题(Yahtzee问题),并将您的代码提交为
所以滚动Yahtzee的概率是1/1296或约.077%
这是我运行模拟的代码:
import random
def runYahtzee(numTrials):
"""Runs the classes version of the yahtzee simulation"""
success = 0
for i in range(numTrials):
dices = []
for i in range(6):
dices.append(random.randrange(1,7))
#print dices
state = True
for dice in dices:
if dice != dices[0]:
state = False
if state == True:
print "You got a Yahtzee"
print dices
success += 1
print "numTrials is: " + str(numTrials)
print "Success is: " + str(success)
rate = float(success)/numTrials
return rate
runYahtzee(10000000) …Run Code Online (Sandbox Code Playgroud) 因此,尝试在PowerShell中对服务器上的文件夹进行简单try/ catch更新共享访问。
try {
Grant-SmbShareAccess -Name [FolderName] -AccountName [GroupToShare] -AccessRight Read -Force
Grant-SmbShareAccess -Name [FolderName] -AccountName [GroupToShare] -AccessRight Read -Force
} catch {
Write-Host "Error Granting one or more permission: $_" -ForegroundColor DarkMagenta
}
Run Code Online (Sandbox Code Playgroud)
是否可以捕获特定的授权访问语句并打印失败的组名。
说我有两个小组:
并且这Grant-SmbShareAccess两个组都失败了,我可以捕获并打印出:
权限失败:NA \ admin 权限失败:NA \ dev
只用一个试钩?
python ×3
list ×1
matplotlib ×1
montecarlo ×1
powershell ×1
python-2.7 ×1
reverse ×1
simulation ×1
try-catch ×1