Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
sorry I deleted this code I do not need help
import numpy as np
import gym
import matplotlib
import matplotlib.pyplot as plt
import tensorflow as tf
from env.BeamEnv import BeamEnv
if statements are vital for an application. As they are part of Dijkstra 1966 model of structured programming ingredients (Sequence, Repeatation, Selection) which still applies today for other paradigm like OOP, POP, FP, FRP, ...
And you are not using them excessively (which could raise a red flag i.e switch statement).
However I would like to recommend to merge your two if conditions if you are not suppose render when you want to export frames. I don’t know what _render() function does but if it is only of use when you need to export frames, you should have put it in the main if to prevent calling unnecessary functions (init_plt() and _render())
if render and self.episode_count % self.sample_freq == 0:
self._init_plt()
self._render(obs)
self.export_frames()
self.episode_count += 1
If you adopt the above code I would like to put your conditions into a functions which returns a boolean.
if self.should_render(self.episode_count):
self.init_plt()
self._render(obs)
self.export_frames()
self.episode_count += 1
Still if you always use init_plt() and _render() together, you may consider, writing a wrapper function which calls them both. Just make the main logic of your code more readable. See Robert Martin (uncle bob) talks on clean codes.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
So I've been trying to learn Python and after some easy codes (or whatever they are called) I am now trying to recreate a drinkinggame i always play with some friends. But for that i need this function to return a value which it doesn't do. Can anyone help me? (sorry for the bad English)
def throw():
dice = 6
List = []
i = 0
while i <= dice - len(List):
i +=1
List.append(random.randint(1,6))
return List
print(throw(List))
Your function isn't receiving any parameter, so don't pass anything.
import random
def throw():
dice = 6
List = []
i = 0
while i <= dice - len(List):
i +=1
List.append(random.randint(1,6))
return List
print(throw()) # here
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
A friend sent me this code and I think it is unsafe and someone tell me.
import random
import os
x = 1
Applications = ["vlc.exe","System","smss.exe","csrss.exe","wininit.exe",
"csrss.exe","winlogon.exe","services.exe","lsass.exe","svchost.exe",
"svchost.exe","dwm.exe","WUDFHost.exe","SEDService.exe","vmacthlp.exe",
"SavService.exe","spoolsv.exe","activcontrolsvc.exe","mDNSResponder.exe",
"armsvc.exe","EwServer.exe","sqlservr.exe","AGSService.exe",
"SAVAdminService.exe","remotesolverdispatcherser","sqlwriter.exe",
"swc_service.exe","SophosCleanM.exe","sqlbrowser.exe",
"SophosSafestore64.exe","McsAgent.exe","SophosHealth.exe","McsClient.exe",
"VGAuthService.exe","USBDLM.exe","SynTPEnhService.exe","Memory_Compression",
"dispatcher.exe","SophosFS.exe","conhost.exe","SophosFileScanner.exe",
"SSPService.exe","dllhost.exe","msdtc.exe","unsecapp.exe","notepad.exe",
"wscript.exe","sihost.exe","taskhostw.exe","USBDLM_usr.exe",
"RuntimeBroker.exe","nexplorer.exe","SynTPEnh.exe","ShellExperienceHost.exe",
"SearchIndexer.exe","SearchUI.exe","GoogleCrashHandler.exe",
"GoogleCrashHandler64.exe","activmgr.exe","ImperoGuardianSVC.exe",
"ImperoClientSVC.exe","igfxtray.exe","hkcmd.exe","igfxpers.exe",
"Sophos_UI.exe","Spotify.exe","FOGUserService.exe","sldworks_fs.exe",
"audiodg.exe","ImperoRelay.exe","ImperoClient.exe",
"ImperoWinlogonApplication","alg.exe","FOGService.exe","rundll32.exe",
"WmiPrvSE.exe","SearchProtocolHost.exe","MetroAppInterface.exe","Code.exe",
"CodeHelper.exe","conhost.exe","python.exe","conhost.exe",
"SearchFilterHost.exe","chrome.exe","backgroundTaskHost.exe","Discord.exe",
"pythonw.exe","tasklist.exe","conhost.exe"]
while x == 1:
Stop_This_Application = random.choice(Applications)
os.system("TASKKILL /F /IM " + Stop_This_Application)
The code will try to stop randomly all the applications listed in the Applications list.
After a reboot, the system will work as usual.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
This is all of the code in my while loop. I have declared the num outside the def statement jest so I don't get a global variable error.
Do you need to call all of the other def statements back to the loop?
num = 0;
def Loop(NumOfFeedback, num):
while num < NumOfFeedback:
classOne(Math,Science,English,History,Band,Choir,Spanish,French,German)
workloadOne(Little,Medium,aLot)
classTwo(MathA,ScienceA,EnglishA,HistoryA,BandA,ChoirA,SpanishA,FrenchA,GermanA)
workloadTwo(LittleA,MediumA,aLotA)
GPA(FourPO,ThreePFive,ThreePO,TwoPFive,TwoPO)
Age(A14,B15,C16,D17,E18)
num = num + 1
print num
You are only defining Loop but you are probably not running it.
When you def a function you just save it, but in order to run it you have to call it from your code.
add this at the end of your code (with the values you need):
Loop([NumOfFeedback], num)
You should change the name of the function to be lowercased (and other than just loop - super not clear).
Also move num = 0 down - right above the call.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to use step number in my Python script. This step number should be auto incrementing and I want to put it as part of logger. Is there any default option available for that?
The simplest way is to just wrap the logging call.
def step_log(message, *args, **kwargs):
logging.info("Step %d:" % step_log.counter + message, *args, **kwargs)
step_log.counter += 1
step_log.counter = 1
This could work in your case
`
step = 0
def sync_step():
global step
step = step+1
logging.info("message", sync_step())
logging.info("message", sync_step())
logging.info("message", sync_step())
print step # answer 3
`