Link object to parent at keyframe in blender using python script - python

I want to link an object to its parent at frame 40 and unlink at frame 80. I feel like it should be something like this:
o.parent = p
o.keyframe_insert(data_path="???", index=-1, frame=40)
o.parent = None
o.keyframe_insert(data_path="???", index=-1, frame=80)
Thanks!

After googling and experimenting I have come up with a small example of how to set and unset (aka influence) a Child Of constraint.
import bpy
def add_frame(oArgObject, sArgType, dArgFrame, sArgName):
if sArgType == 'location':
oArgObject.keyframe_insert(data_path='location', index=-1, frame=dArgFrame)
elif sArgType == 'influence':
oArgObject.keyframe_insert(data_path='constraints["'+sArgName+'"].influence', frame=dArgFrame)
else:
print('Unrecognized frame option: ' + sArgType)
def add_parent(oArgChild, oArgParent, bArgScale):
sName = 'Child' + oArgChild.name + 'Parent' + oArgParent.name
if sName in oArgChild.constraints:
print('Constraint ' + sName + ' exists')
else:
oConst = oArgChild.constraints.new(type = 'CHILD_OF')
oConst.name = sName
oConst.target = oArgParent
oConst.use_scale_x = bArgScale[0]
oConst.use_scale_y = bArgScale[1]
oConst.use_scale_z = bArgScale[2]
print('Constraint ' + sName + ' added')
def set_influence(oArgChild, oArgParent, dArgFrame, dArgInfluence):
sName = 'Child' + oArgChild.name + 'Parent' + oArgParent.name
if sName in oArgChild.constraints:
index = 0
while oArgChild.constraints[index].name != sName:
index += 1
o = oArgChild.constraints[index]
o.influence = 1 - dArgInfluence
add_frame(oArgChild, 'influence', dArgFrame-1, sName)
o.influence = dArgInfluence
add_frame(oArgChild, 'influence', dArgFrame, sName)
else:
print('No constraints exists for object ' + oArgChild.name)
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
bpy.ops.mesh.primitive_cube_add(size = 1, location = (1,0,0))
oParent1 = bpy.context.object
oParent1.scale = (0.5, 1.0, 0.5)
oParent1.name = 'Parent1'
add_frame(oParent1, 'location', 10, 'n/a')
oParent1.location.x += 4
add_frame(oParent1, 'location', 50, 'n/a')
bpy.ops.mesh.primitive_cube_add(size = 1, location = (0,1,0))
oParent2 = bpy.context.object
oParent2.scale = (1.0, 0.5, 0.5)
oParent2.name = 'Parent2'
add_frame(oParent2, 'location', 60, 'n/a')
oParent2.location.y += 4
add_frame(oParent2, 'location', 100, 'n/a')
bpy.ops.mesh.primitive_cube_add(size = 1, location = (0,0,1))
oChild = bpy.context.object
oChild.scale = (0.5, 0.5, 1.0)
oChild.name = 'Child'
add_frame(oChild, 'location', 5, 'n/a')
add_parent(oChild, oParent1, (True,True,True))
add_parent(oChild, oParent2, (False,False,False))
set_influence(oChild, oParent1, 20, 1)
set_influence(oChild, oParent1, 40, 0)
set_influence(oChild, oParent2, 70, 1)
set_influence(oChild, oParent2, 90, 0)

Related

If the value recieved in a Decimal Form is an empty string how can I convert it to a float number?

On my page I ask for various things to the user in the form as it's a calculator that does various things, now you see, the thing is if the user does not have the value for bf I want to give the option to calculate with different values, that is why I required is False, so first what I want to archive is that if the form is empty I want to be passed as a 0 or False, how can I archive this?
I have the following form:
class CMForm(forms.Form):
age = forms.DecimalField(max_digits=2, decimal_places=0, min_value=15, max_value=80)
sex = forms.ChoiceField(choices=sex)
pregnant = forms.BooleanField(initial=False, required=False)
lactating = forms.BooleanField(initial=False, required=False)
weight = forms.DecimalField(max_digits=4, decimal_places=1, max_value=635)
height = forms.DecimalField(max_digits=4, decimal_places=1, max_value=272)
bf = forms.DecimalField(label='Body Fat(not required)', help_text='%', required=False, decimal_places=1, min_value=1, max_value=80)
activeness = forms.ChoiceField(choices=activity_level)
units = forms.ChoiceField(choices=units)
this view:
def cmr(request):
a = float(request.GET['age'])
bf = float(request.GET.get('bf', 0))
s = str(request.GET['sex'])
g = 0
if s == 'female':
g = 1
w = float(request.GET['weight'])
h = float(request.GET['height'])
act = str(request.GET['activeness'])
u = str(request.GET['units'])
p = str(request.GET.get('pregnant', 0))
lac = str(request.GET.get('lactating', 0))
dci = 0
bmrm = 10*w+6.25*h-5*a+5
bmrf = 10*w+6.25*h-5*a-161
bmi = round(w/(h/100)**2, 1)
if bf is False:
bf = round(-44.988 + (0.503 * a) + (10.689 * g) + (3.172 * bmi) - (0.026 * bmi**2) + (0.181 * bmi * g) - (0.02 * bmi * a) - (0.005 * bmi**2 * g) + (0.00021 * bmi**2 * a), 1)
tbf = w*(bf/100)
ffm = w*(1-(bf/100))
ffmi = ffm/(h/100)**2
nffmi = ffmi+6.1*(1.8-(h/100))
if p == 'on':
dci = 300
if lac == 'on':
dci = dci+500
if s == 'male':
bmr = dci+bmrm
dcis = bmrm*1.2
dcil = bmrm*1.375
dcim = bmrm*1.55
dciv = bmrm*1.725
dcie = bmrm*1.9
else:
bmr = dci+bmrf
dcis = dci+bmrf*1.2
dcil = dci+bmrf*1.375
dcim = dci+bmrf*1.55
dciv = dci+bmrf*1.725
dcie = dci+bmrf*1.9
context = {'dci': round(int(dci)),
'p': p,
'lac': lac,
'bmr': int(bmr),
'dcis': int(dcis),
'dcil': int(dcil),
'dcim': int(dcim),
'dciv': int(dciv),
'dcie': int(dcie),
'act': act,
'bmi': bmi,
'bf': bf,
'tbf': round(tbf, 1),
'ffm': round(ffm, 1),
'ffmi': round(ffmi, 1),
'nffmi': round(nffmi, 1),
}
return render(request, "calorie_maintenance_result.html", context)
And I get the following error:
could not convert string to float: ''
You can use or; given a string s, s or 0 will evaluate to 0 if s is empty:
s = ''
print(float(s or 0)) # 0.0
s = '123'
print(float(s or 0)) # 123.0
This happens because (in python) x or y returns x if x is true, and y if x is false. Since an empty string is "falsy", '' or 0 is equal to 0.

I'm getting an error "<built-in function connectSlotsByName> returned a result with an error set" when I use __slots__

I'm trying to make a gui with pyqt5. The code works fine when I don't have the varaibales under __slots__ but once I put them in I get an error saying
"(built-in function connectSlotsByName) returned a result with an error set"
and on the top of the error it says
"'MainWindow' object has no attribute 'z'"
Below is part of my code(which is sort of long). I'm not even sure if the __slots__ is a problem. Because it worked fine when I had from 'fName' to 'has_data', but as soon as I added things under 'x', it started to give me that error.
class MainWindow(QDialog):
__slots__ = (
# find_file_Callback
'fName',
'cubefilename',
'ROI',
'ROIcount',
'has_data',
'x',
'x_end',
'y',
'y_end',
'z',
'ptflag',
'rgflag',
'rgflagROI',
'intens'
)
def __init__(self):
super(MainWindow,self).__init__()
loadUi("ptype1.ui",self)
self.find_file.clicked.connect(self.find_file_Callback)
self.micrometer.setChecked(True)
self.start_cube.clicked.connect(self.start_cube_Callback)
self.fName = ""
self.cubefilename = ""
self.ROI = 0
self.ROIcount = 0
self.has_data = 0
self.x = 0
self.x_end = 0
self.y = 0
self.y_end = 0
self.z = 0
self.ptflag = False
self.rgflag = False
self.rgflagROI = False
self.intens = 0
def start_cube_Callback(self):
self.cubefilename = self.fName[0]
filename = self.cubefilename
print("Working to read datacube")
fileID = open (filename)
data = np.fromfile(fileID, dtype = np.float32)
x=int(data[0])
y=int(data[1])
z=int(data[2])
end = len(data)
imgZ = data[end-z:end]
img = data[3:x*y*z +3]
del data
img = img.reshape(z,x,y, order = 'F')
img = img.transpose(2, 1, 0)
img = np.flip(img,0)
imgX = np.arange(37.5, 75*x+37.5, 75)
imgY = np.arange(75, 150*y+75, 150)
fileID.close()
print("Working to display data\n")
scalefact = 1e3
self.x = abs((imgX-imgX[0])/scalefact)
xm, xn = 1, len(imgX)
if xm > xn:
self.x = self.x.conj().T
self.x_end = self.x[len(self.x) - 1]
self.y = abs((imgY-imgY[0])/scalefact)
ym, yn = 1, len(imgY)
if ym < yn:
self.y = self.y.conj().T
self.y_end = self.y[len(self.y) - 1]
self.z = imgZ

Maya script that renders to frame buffer keeps grabbing focus on windows

I have a script in Maya (python) that renders a series of frames to the V-ray frame buffer, one for each render layer. It is working well, but when switching render layers and launching the next render, Maya grabs focus, interrupting whatever task the artist had moved on to while the script was running. I would like this to be a background task. Maya is running on Windows.
import maya
import maya.cmds as cmds
import re
from functools import partial
import sys
from datetime import datetime
global cancel
cancel = 0
print 'batch_review'
def no_cam_window_popup(no_cam_set_list):
#print no_cam_set_list
cmds.window(title = 'WARNING: NO CAMERAS LINKED TO LAYERS', width = 300, height = 75, sizeable = False)
cmds.columnLayout("mainColumn", adjustableColumn = True)
cmds.rowLayout("nameRowLayout01", numberOfColumns = 15, parent = "mainColumn")
cmds.text(label = ("no cam set for layers:"))
for layer in no_cam_set_list:
cmds.text(label = ('' + layer + ', '),font = 'boldLabelFont')
cmds.showWindow()
def renderThumbs(checkBoxLow,checkBoxMid,checkBoxHigh,checkBoxRenderRegion,intField_res,floatField_thrhld,*args):
global cancel
cams = cmds.ls(type = "camera")
cancel = 0
popup_win = 0
no_cam_set_list = []
cmds.loadPlugin('vrayformaya', quiet=True)
cmds.pluginInfo('vrayformaya', edit=True, autoload=True)
cmds.setAttr("defaultRenderGlobals.ren", "vray", type = "string")
curLay = cmds.editRenderLayerGlobals( currentRenderLayer = True, query = True )
changeLay = curLay
rls = cmds.ls(type = "renderLayer")
renCams = cmds.ls(type = "camera")
renCam = "persp"
lowBut = cmds.checkBox(checkBoxLow,value = True, query = True)
midBut = cmds.checkBox(checkBoxMid,value = True, query = True)
highBut = cmds.checkBox(checkBoxHigh,value = True, query = True)
globopt_cache_geom_plugins = cmds.getAttr('vraySettings.globopt_cache_geom_plugins')
#print 'globopt_cache_geom_plugins = ',globopt_cache_geom_plugins
print " "
print "-- batch_review --"
res = cmds.intField(intField_res, v = True, query = True)
thr = cmds.floatField(floatField_thrhld, v = True,query = True)
if lowBut == 1:
cmds.setAttr("vraySettings.dmcThreshold",thr)
cmds.setAttr("vraySettings.width", res)
cmds.setAttr("vraySettings.height", res)
cmds.setAttr("vraySettings.globopt_cache_geom_plugins",1)
cmds.setAttr("vraySettings.globopt_ray_maxIntens_on",1)
#cmds.setAttr('vraySettings.globopt_cache_geom_plugins',globopt_cache_geom_plugins)
print " "
print "---"
print "quality = %s, dmcThreshold = %s"%(res,thr)
if midBut == 1:
cmds.setAttr("vraySettings.dmcThreshold",thr)
cmds.setAttr("vraySettings.width", res)
cmds.setAttr("vraySettings.height", res)
cmds.setAttr("vraySettings.globopt_cache_geom_plugins",1)
cmds.setAttr("vraySettings.globopt_ray_maxIntens_on",1)
#cmds.setAttr('vraySettings.globopt_cache_geom_plugins',globopt_cache_geom_plugins)
print " "
print "---"
print "quality = %s, dmcThreshold = %s"%(res,thr)
if highBut == 1:
cmds.setAttr("vraySettings.dmcThreshold",thr)
cmds.setAttr("vraySettings.width", res)
cmds.setAttr("vraySettings.height", res)
cmds.setAttr("vraySettings.globopt_cache_geom_plugins",1)
cmds.setAttr("vraySettings.globopt_ray_maxIntens_on",1)
#cmds.setAttr('vraySettings.globopt_cache_geom_plugins',globopt_cache_geom_plugins)
print " "
print "---"
print "quality = %s, dmcThreshold = %s"%(res,thr)
print "--- "
print " "
for rl in rls:
found_cam = 0
if rl != "defaultRenderLayer" and cancel == 0:
rlState = cmds.getAttr(rl + ".renderable")
if rlState == 1:
print ' '
print "rende layer = ",rl
cmds.editRenderLayerGlobals( currentRenderLayer = rl )
for cam in cams:
camState = cmds.getAttr(cam + ".renderable")
if camState == 1:
rrState = cmds.checkBox(checkBoxRenderRegion,value = True,query = True)
reg = cmds.vray("vfbControl","-getregion")
if rrState == 0:
cmds.vray("vfbControl","-setregion","reset")
if rrState == 1:
cmds.vray("vfbControl","-setregionenabled",1)
cmds.vray("vfbControl","-setregion",reg[0],reg[1],reg[2],reg[3])
mayaString = "renderWindowRenderCamera render renderView " + cam
print 'using ' + cam + ' for ' + rl
maya.mel.eval(mayaString)
cmds.vray("vfbControl", "-historysave")
cmds.vray("vfbControl", "-historyselect",0)
dte = datetime.now().strftime('%H:%M:%S')
editStr = dte + " ,render layer: " + rl + " , " + "cam: " + cam
cmds.vray("vfbControl", "-historycomment", editStr)
print " "
found_cam = 1
if found_cam == 0:
print 'no camera link found, using persp cam for ',rl
cam = 'persp'
rrState = cmds.checkBox(checkBoxRenderRegion,value = True,query = True)
reg = cmds.vray("vfbControl","-getregion")
if rrState == 0:
cmds.vray("vfbControl","-setregion","reset")
if rrState == 1:
cmds.vray("vfbControl","-setregionenabled",1)
cmds.vray("vfbControl","-setregion",reg[0],reg[1],reg[2],reg[3])
mayaString = "renderWindowRenderCamera render renderView " + cam
maya.mel.eval(mayaString)
cmds.vray("vfbControl", "-historysave")
cmds.vray("vfbControl", "-historyselect",0)
dte = datetime.now().strftime('%H:%M:%S')
editStr = dte + " ,render layer: " + rl + " , " + "cam: " + cam
cmds.vray("vfbControl", "-historycomment", editStr)
popup_win = 1
no_cam_set_list.append(rl)
#if popup_win == 1:
#no_cam_window_popup(no_cam_set_list)
def checkBoxCheckLow(checkBoxLow,checkBoxMid,checkBoxHigh,intField_res,floatField_thrhld,*args):
global cancel
lowButVal = cmds.checkBox(checkBoxLow,value = True, query = True)
midButVal = cmds.checkBox(checkBoxMid,value = True, query = True)
highButVal = cmds.checkBox(checkBoxHigh,value = True, query = True)
cmds.checkBox(checkBoxMid,value = False, edit = True)
cmds.checkBox(checkBoxHigh,value = False, edit = True)
cmds.intField(intField_res, v = 800,edit = True)
cmds.floatField(floatField_thrhld, v = .1,edit = True )
cancel = 0
def checkBoxCheckMid(checkBoxLow,checkBoxMid,checkBoxHigh,intField_res,floatField_thrhld,*args):
global cancel
lowButVal = cmds.checkBox(checkBoxLow,value = True, query = True)
midButVal = cmds.checkBox(checkBoxMid,value = True, query = True)
highButVal = cmds.checkBox(checkBoxHigh,value = True, query = True)
cmds.checkBox(checkBoxLow,value = False, edit = True)
cmds.checkBox(checkBoxHigh,value = False, edit = True)
cmds.intField(intField_res, v = 1000,edit = True)
cmds.floatField(floatField_thrhld, v = .5,edit = True )
cancel = 0
def checkBoxCheckHigh(checkBoxLow,checkBoxMid,checkBoxHigh,intField_res,floatField_thrhld,*args):
global cancel
lowButVal = cmds.checkBox(checkBoxLow,value = True, query = True)
midButVal = cmds.checkBox(checkBoxMid,value = True, query = True)
highButVal = cmds.checkBox(checkBoxHigh,value = True, query = True)
cmds.checkBox(checkBoxLow,value = False, edit = True)
cmds.checkBox(checkBoxMid,value = False, edit = True)
cmds.intField(intField_res, v = 2000,edit = True)
cmds.floatField(floatField_thrhld, v = .008,edit = True )
cancel = 0
def checkBoxAOVchange(checkBoxAOV,*args):
checkBoxAOVval = cmds.checkBox(checkBoxAOV,value = True,query = True)
if checkBoxAOVval == 1:
cmds.setAttr("vraySettings.relements_enableall", 1)
if checkBoxAOVval == 0:
cmds.setAttr("vraySettings.relements_enableall", 0)
def rrCheckbox(checkBoxRenderRegion,reg,*args):
global gReg
zeroes = ['0','0','0','0']
tRes = cmds.vray("vfbControl","-getregion")
if tRes != zeroes:
gReg = tRes
rrstate = cmds.checkBox(checkBoxRenderRegion,value = True,query = True)
if rrstate == 0:
if gReg != zeroes:
cmds.vray("vfbControl","-setregion",gReg[0],gReg[1],gReg[2],gReg[3])
else:
cmds.vray("vfbControl","-setregion",reg[0],reg[1],reg[2],reg[3])
cmds.vray("vfbControl","-setregion","reset")
if rrstate == 1:
cmds.vray("vfbControl","-setregionenabled",1)
if gReg != zeroes:
cmds.vray("vfbControl","-setregion",gReg[0],gReg[1],gReg[2],gReg[3])
else:
cmds.vray("vfbControl","-setregion",reg[0],reg[1],reg[2],reg[3])
return(reg)
def cancelOPs(*args):
global cancel
cancel = 1
raise Exception("quitting renders")
def set_threshhold(floatField_thrhld,*args):
threshhold_value = cmds.floatField(floatField_thrhld,value = True,query = True)
cmds.setAttr('vraySettings.dmcThreshold',threshhold_value)
def set_resolution(intField_res,*args):
intField_res_value = cmds.intField(intField_res,value = True,query = True)
cmds.setAttr('vraySettings.width',intField_res_value)
cmds.setAttr('vraySettings.height',intField_res_value)
def renthumbsWin():
name = "Batch_Review"
global gReg
gReg = ('0','0','0','0')
zeroes = ('0','0','0','0')
windowSize = (200,100)
if (cmds.window(name, exists = True)):
cmds.deleteUI(name)
window = cmds.window(name, title = name, width = 350, height = 50,bgc = (.2,.2,.2), s = False)
cmds.columnLayout("mainColumn", adjustableColumn = True)
cmds.rowLayout("nameRowLayout01", numberOfColumns = 15, parent = "mainColumn")
cmds.text(label = "preset quality: ")
checkBoxLow = cmds.checkBox(label = "low", value = False)
checkBoxMid = cmds.checkBox(label = "mid", value = True,)
checkBoxHigh = cmds.checkBox(label = "high", value = False)
cmds.text(label = " ")
cmds.text(label = "resolution: ")
intField_res = cmds.intField(v = 1000,width = 45)
#print 'intField_res = ',intField_res
cmds.intField(intField_res, changeCommand = partial(set_resolution,intField_res),edit = True)
cmds.text(label = " ")
cmds.text(label = "threshold: ")
floatField_thrhld = cmds.floatField(v = .5,width = 45)
cmds.floatField(floatField_thrhld, changeCommand = partial(set_threshhold,floatField_thrhld),edit = True)
cmds.checkBox(checkBoxLow, changeCommand = partial(checkBoxCheckLow,checkBoxLow,checkBoxMid,checkBoxHigh,intField_res,floatField_thrhld), edit = True)
cmds.checkBox(checkBoxMid, changeCommand = partial(checkBoxCheckMid,checkBoxLow,checkBoxMid,checkBoxHigh,intField_res,floatField_thrhld),edit = True)
cmds.checkBox(checkBoxHigh, changeCommand = partial(checkBoxCheckHigh,checkBoxLow,checkBoxMid,checkBoxHigh,intField_res,floatField_thrhld),edit = True)
cmds.rowLayout("nameRowLayout02", numberOfColumns = 10, parent = "mainColumn")
cmds.text(label = " ")
cmds.rowLayout("nameRowLayout03", numberOfColumns = 5, parent = "mainColumn")
renderButton = cmds.button(label = "render",width = 100, bgc = (.6,.8,1) )
cmds.text(label = " ")
cmds.button(label = "cancel renders", command = partial(cancelOPs),bgc = (1,.3,.3) )
cmds.rowLayout("nameRowLayout04", numberOfColumns = 10, parent = "mainColumn")
cmds.text(label = " ")
cmds.rowLayout("nameRowLayout05", numberOfColumns = 10, parent = "mainColumn")
checkBoxRenderRegion = cmds.checkBox(label = "use render region", value = False)
cmds.text(label = " ")
cmds.text(label = " ")
reg = cmds.vray("vfbControl","-getregion")
if reg != gReg and reg != zeroes:
gReg = reg
cmds.vray("vfbControl","-setregion","reset")
cmds.checkBox(checkBoxRenderRegion,changeCommand = partial(rrCheckbox,checkBoxRenderRegion,reg),edit = True)
cmds.rowLayout("nameRowLayout06", numberOfColumns = 10, parent = "mainColumn")
AOVstate = cmds.getAttr("vraySettings.relements_enableall")
checkBoxAOV = cmds.checkBox(label = "elements", value = AOVstate)
cmds.checkBox(checkBoxAOV,changeCommand = partial(checkBoxAOVchange,checkBoxAOV),edit = True)
cmds.button(renderButton,command = partial(renderThumbs,checkBoxLow,checkBoxMid,checkBoxHigh,checkBoxRenderRegion,intField_res,floatField_thrhld),edit = True)
cmds.showWindow()
def main():
renthumbsWin()
main()

Ploting results from Gurobi python

import os
import sys
import math
import cvxopt as cvx
import picos as pic
import pandas as pd
import matplotlib.pyplot as plt
from gurobipy import *
from statsmodels.tsa.arima_model import ARIMA
import numpy as np
from scipy import *
#import DeferableLoad
OPTmodel = Model('OPTIMIZER')
#general parameters
Tamb =22
N = 1440 # maximum iteration
i = range(1, N)
COP= 3.4 # Coeffient of performance
'''
Prediction need to be added here
'''
# Datacenter room defintion
R = 10 #length of room
B = 7
H = 9 #Height of room
L = 10
dT = 60
A = 2*((L*B)+(B*H)+(H*L))
Thick = 0.33 # thickness of wall
k = 0.7 # thermal conductivity of wall
mAir = 1.2 * (L * B * H)
C = 718
landa = k * A / Thick
a0 = 0.05 / dT
a1 = 1
ki = math.exp(-(landa * 60) / (mAir * C)) # value that constant and its related to property of room
kc = (1 - ki) * a0
ko = (1 - ki) * a1
kp = (1 - ki) * (COP / landa)
Tmin= 18
Tmax= 27
Tamb= 22
PcoolingRated = 100
Pbess_rated = 30.462
Pbess_ratedN = -30.462
Ebess_min = 0
Ebess_max = 300
with open ('Pcooling.csv','r') as f:
Pcooling = []
for line in f:
Pcooling.append(line)
f.close()
with open ('ITpower.csv','r') as f1:
ITload = []
for line1 in f1:
ITload.append(line1)
f1.close()
with open ('DR.csv','r') as f2:
DR =[]
for line2 in f2:
DR.append(line2)
f2.close()
print ITload
print Pcooling
print DR
for i in range(1,200):
for it in range(1, 1440):
Tm = np.empty(1440)
Tm.fill(18)
TmA = np.empty(1440)
TmA.fill(27)
Phvac_flex = {}
Phvac_up = {}
Phvac_down_= {}
Phvac_up_ = {}
Pbess_out_ = {}
Pbess_in_ = {}
Phvac_down = {}
Pbess_flex_ = {}
Pbess_flex = {}
Phvac_flex_ = {}
Pbess_in = {}
Pdc = {}
Pdc_base = {}
Pflex_i = {}
Tdc_i = {}
Pbess_out ={}
Ebess_i = {}
Phvac_flex[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS,name="PHVAC_flex"+str(i))
Phvac_up[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PHVAC_up" + str(i))
Phvac_up_[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PHVAC_up_" + str(i))
Phvac_down_[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PHVAC_down_" + str(i))
Pbess_out_[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PBESS_out_" + str(i))
Pbess_in_[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PBESS_in_" + str(i))
Phvac_down[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PHVAC_down" + str(i))
Pbess_flex_[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PBESS_flex_" + str(i))
Pbess_flex[i] = OPTmodel.addVar(lb=-GRB.INFINITY,ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PBESS_flex" + str(i))
Phvac_flex_[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PHVAC_flex_" + str(i))
Pbess_in[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PBESS_in" + str(i))
Pdc[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PDC" + str(i))
Pdc_base[i] = OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PDC_base" + str(i))
Pflex_i[i]= OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="Pflex_i" + str(i))
Tdc_i[i]= OPTmodel.addVar(ub=GRB.INFINITY,vtype = GRB.CONTINUOUS, name = "Tdc_i" + str(i))
Pbess_out[i] = OPTmodel.addVar(lb=-GRB.INFINITY,ub=GRB.INFINITY,vtype=GRB.CONTINUOUS, name="PBESS_out" + str(i))
Ebess_i[i]= OPTmodel.addVar(ub=GRB.INFINITY,vtype=GRB.CONTINUOUS,name="Ebess_i" + str(i))
Pflex_i[1] = 0
Pflex_i[1] = 0
Tdc_i[0] = 18
Phvac_flex[1] = 0
# Phvac_flex_[1] = 0
Phvac_down[1] = 0
Phvac_up[1] = 0
Phvac_down_[1] = 0
Phvac_up_[1] = 0
# Phvac_down_pos[1] = 0
# Phvac_up_pos(1) = 0;
Pbess_flex[1] = 0
# Pbess_flex_[1] = 0
Pbess_out[1] = 0
Pbess_in[1] = 0
# Pbess_out_[1] = 0
Pbess_in_[1] = 0
# Pbess_out_pos[1] = -250
# Pbess_in_pos(1) = 250;
Ebess_i[1] = 150
OPTmodel.update()
'''
if float(DR[i]) > 0:
Phvac_down_[i] = 0
Phvac_up_[i] = float(DR[i])
Pbess_out_[i] = 0
Pbess_in_[i] = float(DR[i])
#Pbess_flex_[i] = Pbess_in_[i] + Pbess_out_[i]
#Phvac_flex_[i] = Phvac_down_[i] + Phvac_up_[i]
OPTmodel.update()
elif float(DR[i]) < 0:
Phvac_down_[i] = float(DR[i])
Phvac_up_[i] = 0
#Phvac_flex_[i] = Phvac_down_[i] + Phvac_up_[i]
Pbess_out_[i] = float(DR[i])
Pbess_in_[i] = 0
#Pbess_flex_[i] = Pbess_in_[i] + Pbess_out_[i]
OPTmodel.update()
else:
Phvac_down_[i] = 0
Phvac_up_[i] = 0
Phvac_flex_[i] = Phvac_down_[i] + Phvac_up_[i]
Pbess_out_[i] = 0
Pbess_in_[i] = 0
Pbess_flex_[i] = Pbess_in_[i] + Pbess_out_[i]
OPTmodel.update()
'''
#print Phvac_up.values()
#print Phvac_flex_[i]
print OPTmodel
OPTmodel.update()
ConHVAC1 = OPTmodel.addConstr(Phvac_flex[i] == Phvac_up[i] + Phvac_down[i], name='ConHVAC1')
ConHVAC2 = OPTmodel.addConstr(0 <= Phvac_flex[i] , name='ConHVAC2')
ConHVAC3 = OPTmodel.addConstr(Phvac_flex[i] <= PcoolingRated, name='ConHVAC3')
PH = pd.read_csv('Pcooling.csv')
PHVAC = PH.values
newList2 = map(lambda x: x / 1000, PHVAC)
p=[]
p=PcoolingRated-newList2[i]
#CONHVAC4 = OPTmodel.addConstr(Phvac_up[i]==np.minimum((Phvac_up_[i]),(float(newList2[i]))))
#Phvac_u(1:MaxIter) == min(Phvac_u_(1:MaxIter), (repelem(Phvac_max, MaxIter) - (Pcooling(1:MaxIter)'/1000)))
ConTemp1 = OPTmodel.addConstr(Tm[it] <= Tdc_i[i] <= TmA[it], name='ConTemp1')
ConBESS1 = OPTmodel.addConstr(Pbess_ratedN <= Pbess_flex[i] <= Pbess_rated, name='ConBESS1')
ConBESS2 = OPTmodel.addConstr(Pbess_flex[i] == Pbess_in[i] + Pbess_out[i], name='ConBESS2')
ConBESS3 = OPTmodel.addConstr(0 <= Pbess_in[i] <= min(Pbess_rated, Pbess_in_[i]), name='ConBESS3')
ConBESS4 = OPTmodel.addConstr(np.maximum(Pbess_ratedN,Pbess_out_[i]) <= Pbess_out[i]<=0 , name='ConBESS4') # need to modifty
ConEBESS1 = OPTmodel.addConstr(Ebess_min <= Ebess_i[i], name='ConEBESS1')
ConEBESS2 = OPTmodel.addConstr(Ebess_i[i] <= Ebess_max, name='ConEBESS2')
D = pd.read_csv('DR.csv').values
DRN = map(lambda x: x / 1000, D)
PDRN=map(lambda x: x / 4.8, DRN)
if float((PDRN[i])) > 0:
CON1 = OPTmodel.addConstr(Pbess_flex_[i] == Pbess_in_[i] + Pbess_out_[i],'CON1')
CON2 = OPTmodel.addConstr(Phvac_flex_[i] == Phvac_up_[i] + Phvac_down_[i],'CON2')
CON3=OPTmodel.addConstr(Phvac_down_[i] == 0, name='CON3')
CON4=OPTmodel.addConstr(Phvac_up_[i] == float((PDRN[i])),name='CON4')
CON5=OPTmodel.addConstr(Pbess_out_[i] == 0,name='CON5')
CON6=OPTmodel.addConstr(Pbess_in_[i] == float((PDRN[i])),name='CON6')
elif float(np.transpose(PDRN[i])) < 0:
CON7=OPTmodel.addConstr(Phvac_down_[i] == float(np.transpose(PDRN[i])),name='CON7')
CON8=OPTmodel.addConstr(Phvac_up_[i] == 0,name='CON8')
# Phvac_flex_[i] = Phvac_down_[i] + Phvac_up_[i]
CON9=OPTmodel.addConstr(Pbess_out_[i] == float((PDRN[i])),name='CON9')
CON10=OPTmodel.addConstr(Pbess_in_[i] == 0,name='CON10')
else:
CON11=OPTmodel.addConstr(Phvac_down_[i] == 0,name='CON11')
CON12=OPTmodel.addConstr(Phvac_up_[i] == 0,name='CON12')
CON13=OPTmodel.addConstr(Phvac_flex_[i] == Phvac_down_[i] + Phvac_up_[i],name='CON13')
CON14=OPTmodel.addConstr(Pbess_out_[i] == 0)
CON15=OPTmodel.addConstr(Pbess_in_[i] == 0,name='CON15')
CON16=OPTmodel.addConstr(Pbess_flex_[i] == Pbess_in_[i] + Pbess_out_[i],name='CON16')
OPTmodel.update()
ConPDC = OPTmodel.addConstr(Pdc[i] == Pflex_i[i] + float(ITload[i]), name='ConPDC')
# OPTmodel.addConstr(Tdc_i[i]==(ki*Tdc_i[i-1]+(ko*Tamb)))
#for x in Ebess_i:
#ConEBESS2 = OPTmodel.addConstr(Ebess_i[i] ==((Pbess_in[i] / 0.75) + (Pbess_out[i] * 0.75)))
cooling = np.array(pd.read_csv('Pcooling.csv'))
DRR = pd.read_csv('DR.csv')
DR = DRR.values
IT = pd.read_csv('ITpower.csv')
ITload = IT.values
newList = map(lambda x: x / 1000, ITload)
PH = pd.read_csv('Pcooling.csv')
PHVAC = PH.values
newList2 = map(lambda x: x / 1000, PHVAC)
#for y in Tdc_i:
T=pd.read_csv('TT.csv').values
OPTmodel.addConstr(Tdc_i[i]==((ki*float(T[i]))+(ko*Tamb)+(kc*float(newList[i]))-((kp*(float(newList2[i])))+(Phvac_flex[i]*3.14))))
print Tdc_i.values()
OPTmodel.addConstr(Pbess_out_[i]<=Phvac_flex[i] + Pbess_flex[i]<=Pbess_in_[i])
# Tdc_i[1:len(i)]==(Ki*Tdc_i[1:1438])+(Kc*array2[1:1438])+(Ko*Tamb))
ConBESS5 = OPTmodel.addConstr(Pbess_flex[i] == Pbess_in[i] + Pbess_out[i], name='ConBESS5')
#OPTmodel.addConstr(defIT[i]==DeferableLoad.j2 + DeferableLoad.j3)
# OPTmodel.addConstr(Pdc_base[i]==predictions[i])
ConFLEX = OPTmodel.addConstr(Pflex_i[i] == Pbess_flex[i] + Phvac_flex[i], name='ConFLEX')
PcoolingPredicted = pd.read_csv('PcoolingPredictionResult.csv')
PcoolingPredictedValue = PcoolingPredicted.values
ITPredicted = pd.read_csv('ITpredictionResult.csv')
ITPredictedValue = ITPredicted.values
ConPDCbase = OPTmodel.addConstr(Pdc_base[i] == np.transpose(ITPredictedValue[i]) + np.transpose(PcoolingPredictedValue[i]))
OPTmodel.update()
# OPTmodel.addConstr(Pdc_base[i]==prediction[i])
OPTmodel.setObjective((np.transpose(Pdc_base[i])-float(DR[i]) - (Pdc[i]) ), GRB.MINIMIZE)
OPTmodel.update()
OPTmodel.optimize()
print Pdc_base[i].X
#print Ebess_i[i].X
#print Phvac_flex[i].X
print Tdc_i[i]
print Pdc[i]
print Phvac_flex[i]
print Pbess_flex[i]
print Pbess_out[i]
print Pbess_in[i]
print Ebess_i[i]
print Pbess_flex_[i]
print Phvac_down[i]
print Phvac_up[i]
'''
def get_results(self):
"""
This function gets the results of the current optimization model
Returns
-------
"""
HVACresult = np.zeros(1,N)
BatteryResult = np.zeros(1,N)
SOC = np.zeros(1,N)
#r_Q_dot = np.zeros((self.gp.N_H, self.N_S))
#r_P = np.zeros((self.gp.N_H, self.N_S))
#r_P_self = np.zeros((self.gp.N_H, self.N_S))
#r_P_ex = np.zeros((self.gp.N_H, self.N_S))
#r_Q_dot_gas = np.zeros((self.gp.N_H, self.N_S))
#Load = np.zeros((self.gp.N_H, self.N_S))
try:
for t in range(1,N):
HVACresult[t]= Phvac_flex[t].X
BatteryResult[t]=Pbess_flex[t].X
SOC[t] = Ebess_i[t].X / Ebess_max
except:
pass
return { 'SOC' : SOC , 'BatteryResult': BatteryResult }
print OPTmodel.getVars()
# get results
Temp = {}
Battery = {}
Ebess_result = {}
ITloadd = {}
for t in range(1,N):
Temp[t] = OPTmodel.getVarByName("Tdc_i" )
Battery[t] = OPTmodel.getVarByName("PBESS_flex" )
Ebess_result[t] = OPTmodel.getVarByName("Ebess_i" )
#r_P_e[t] = model.getVarByName("P_export_%s_0" % t).X
fig, axes = plt.subplots(4, 1)
# plot elctricity
ax5 = axes[2]
ax6 = ax5.twinx()
ax5.plot( [Temp[t] for t in range(1,N)], 'g-')
ax6.plot([Ebess_result[t] for t in range(1,N)], 'b-')
ax5.set_xlabel('Time index')
ax5.set_ylabel('Power Import [W]', color='g')
ax6.set_ylabel('Power CHP [W]', color='b')
ax7 = axes[3]
ax7.plot([Battery[t] for t in range(1,N)], 'g-')
ax7.set_ylabel('Power Export [W]', color='g')
'''
print Pflex_i.values()
# print OPTmodel.getVars()
print OPTmodel.feasibility()
print OPTmodel.getObjective()
print Pdc_base.values()
'''
b = map(float, Phvac_flex)
plt.plot(b)
plt.show()
'''
#c = map(float, Pbess_flex_)
#plt.plot(c)
#plt.show()
print OPTmodel
print Tdc_i.values()
# get results
print OPTmodel.getVars()
# print OPTmodel.getAttr('EBESS_i')
status = OPTmodel.status
print status
# print Con10,Con12
print Phvac_flex.values()
print Pbess_flex.values()
print Ebess_i.values()
print OPTmodel.objval
print Tdc_i
print Pbess_in
print Pbess_out.values()
# print Pbess_flex
# print Phvac_flex
# print Ebess_i
print Pflex_i.values()
print Pbess_flex_.values()
#print OPTmodel.getVars()
print OPTmodel.feasibility()
print OPTmodel.getObjective()
print Ebess_i.values()
if OPTmodel.status == GRB.Status.INF_OR_UNBD:
# Turn presolve off to determine whether model is infeasible
# or unbounded
OPTmodel.setParam(GRB.Param.Presolve, 0)
OPTmodel.optimize()
OPTmodel.write("mymodel.lp")
if OPTmodel.status == GRB.Status.OPTIMAL:
print('Optimal objective: %g' % OPTmodel.objVal)
OPTmodel.write('model.sol')
exit(0)
elif OPTmodel.status != GRB.Status.INFEASIBLE:
print('Optimization was stopped with status %d' % OPTmodel.status)
exit(0)
# Model is infeasible - compute an Irreducible Inconsistent Subsystem (IIS)
print('')
print('Model is infeasible')
OPTmodel.computeIIS()
OPTmodel.write("model.ilp")
print("IIS written to file 'model.ilp'")
I want to plot the computed values from gurobi but when I want to get the X attribute of gurobi variable it says that AttributeError: it has no attribute 'X' and the when I cast the value from float to int it just showed me the empty plot but at the lp file I could see the result of each iteration
I am anxiously waiting for your response
cherrs

If / else statement not working depending on random number (Python)

I'm making a text encrypt-er that randomizes the pattern of symbols used (abcd) but after the first if statement, the program no longer works. New, old, get , and tag are the 4 letter to symbol translations. I tested out only the first if statement by itself and it worked perfectly fine. Also any tips in how to shorten the code would be much appreciated.
our_str = input("Mornin' ")
length = (len(our_str)/2)
rounded = round(length)
import random
rand = random.randint(1,6)
print(rand)
if rand <= 2: #abcd
new_str = our_str[:rounded].replace('a', ']')
new1_str = new_str.replace('b', '◙')
new2_str = new1_str.replace('c', '♂')
new3_str = new2_str.replace('d', 'd')
new4_str = new3_str.replace('e', 'e')
new5_str = new4_str.replace('f', '▓')
new6_str = new5_str.replace('g', '─')
new7_str = new6_str.replace('h', 'Φ')
new8_str = new7_str.replace('i', 'Θ')
new9_str = new8_str.replace('j', '≥')
new10_str = new9_str.replace('k', '≤')
new11_str = new10_str.replace('l', 'L')
new12_str = new11_str.replace('m', 'M')
new13_str = new12_str.replace('n', 'V')
new14_str = new13_str.replace('o', 'W')
new15_str = new14_str.replace('p', '►')
new16_str = new15_str.replace('q', '◄')
new17_str = new16_str.replace('r', '→')
new18_str = new17_str.replace('s', '←')
new19_str = new18_str.replace('t', 't')
new20_str = new19_str.replace('u', 'u')
new21_str = new20_str.replace('v', '~')
new22_str = new21_str.replace('w', '⌂')
new23_str = new22_str.replace('x', '°')
new24_str = new23_str.replace('y', '∙')
new25_str = new24_str.replace('z', '☻')
new26_str = new25_str.replace(' ', 'f')
old_str = our_str[rounded:2 * rounded].replace('a', 'Y')
old1_str = old_str.replace('b', 'É')
old2_str = old1_str.replace('c', 'Θ')
old3_str = old2_str.replace('d', '╩')
old4_str = old3_str.replace('e', 'b')
old5_str = old4_str.replace('f', '█')
old6_str = old5_str.replace('g', '=')
old7_str = old6_str.replace('h', '↑')
old8_str = old7_str.replace('i', 'U')
old9_str = old8_str.replace('j', '⌂')
old10_str = old9_str.replace('k', '┬')
old11_str = old10_str.replace('l', 'æ')
old12_str = old11_str.replace('m', '◄')
old13_str = old12_str.replace('n', '1')
old14_str = old13_str.replace('o', 'B')
old15_str = old14_str.replace('p', 'Ñ')
old16_str = old15_str.replace('q', '╡')
old17_str = old16_str.replace('r', '▌')
old18_str = old17_str.replace('s', '♣')
old19_str = old18_str.replace('t', 'Γ')
old20_str = old19_str.replace('u', 'τ')
old21_str = old20_str.replace('v', '╔')
old22_str = old21_str.replace('w', '░')
old23_str = old22_str.replace('x', '┘')
old24_str = old23_str.replace('y', 'ó')
old25_str = old24_str.replace('z', ';')
old26_str = old25_str.replace(' ', 'ß')
get_str = our_str[2 * rounded:3 * rounded].replace('a', 'ç')
get1_str = get_str.replace('b', '1')
get2_str = get1_str.replace('c', '♣')
get3_str = get2_str.replace('d', 'ⁿ')
get4_str = get3_str.replace('e', '♠')
get5_str = get4_str.replace('f', 'S')
get6_str = get5_str.replace('g', '°')
get7_str = get6_str.replace('h', '♫')
get8_str = get7_str.replace('i', 'D')
get9_str = get8_str.replace('j', '│')
get10_str = get9_str.replace('k', '←')
get11_str = get10_str.replace('l', 'ƒ')
get12_str = get11_str.replace('m', 'Æ')
get13_str = get12_str.replace('n', 'P')
get14_str = get13_str.replace('o', '#') #skipped 0781, 6406
get15_str = get14_str.replace('p', '.') #0899
get16_str = get15_str.replace('q', '┤') #0348
get17_str = get16_str.replace('r', 'µ')
get18_str = get17_str.replace('s', 'E')
get19_str = get19_str.replace('t', '§')
get20_str = get20_str.replace('u', '▬')
get21_str = get21_str.replace('v', 'û')
get22_str = get22_str.replace('w', '♀')
get23_str = get23_str.replace('x', '&')
get24_str = get24_str.replace('y', '≈')
get25_str = get25_str.replace('z', 'ª') #4460
get26_str = get26_str.replace(' ', 'N')
tag_str = our_str[3 * rounded:].replace('a', '╬')
tag1_str = tag_str.replace('b', '↓')
tag2_str = tag1_str.replace('c', '<')
tag3_str = tag2_str.replace('d', '╦')
tag4_str = tag3_str.replace('e', '-')
tag5_str = tag4_str.replace('f', 'δ') #skipped 360
tag6_str = tag5_str.replace('g', '▼')
tag7_str = tag6_str.replace('h', '╫')
tag8_str = tag7_str.replace('i', '`')
tag9_str = tag8_str.replace('j', 'û')
tag10_str = tag9_str.replace('k', '±')
tag11_str = tag10_str.replace('l', '⌡')
tag12_str = tag11_str.replace('m', '≈')
tag13_str = tag12_str.replace('n', ']')
tag14_str = tag13_str.replace('o', '╗')
tag15_str = tag14_str.replace('p', '┐')
tag16_str = tag15_str.replace('q', '>')
tag17_str = tag16_str.replace('r', '╞')
tag18_str = tag17_str.replace('s', '╟') #627
tag19_str = tag18_str.replace('t', '╘')
tag20_str = tag19_str.replace('u', 'L')
tag21_str = tag20_str.replace('v', 'v') #353
tag22_str = tag21_str.replace('w', '#')
tag23_str = tag22_str.replace('x', 'R')
tag24_str = tag23_str.replace('y', ';')
tag25_str = tag24_str.replace('z', '~')
tag26_str = tag25_str.replace(' ', '▓')
print(new26_str + old26_str + get26_str + tag26_str)
elif 2 < rand <= 4 #abdc
new_str = our_str[:rounded].replace('a', ']')
new1_str = new_str.replace('b', '◙')
new2_str = new1_str.replace('c', '♂')
new3_str = new2_str.replace('d', 'd')
new4_str = new3_str.replace('e', 'e')
new5_str = new4_str.replace('f', '▓')
new6_str = new5_str.replace('g', '─')
new7_str = new6_str.replace('h', 'Φ')
new8_str = new7_str.replace('i', 'Θ')
new9_str = new8_str.replace('j', '≥')
new10_str = new9_str.replace('k', '≤')
new11_str = new10_str.replace('l', 'L')
new12_str = new11_str.replace('m', 'M')
new13_str = new12_str.replace('n', 'V')
new14_str = new13_str.replace('o', 'W')
new15_str = new14_str.replace('p', '►')
new16_str = new15_str.replace('q', '◄')
new17_str = new16_str.replace('r', '→')
new18_str = new17_str.replace('s', '←')
new19_str = new18_str.replace('t', 't')
new20_str = new19_str.replace('u', 'u')
new21_str = new20_str.replace('v', '~')
new22_str = new21_str.replace('w', '⌂')
new23_str = new22_str.replace('x', '°')
new24_str = new23_str.replace('y', '∙')
new25_str = new24_str.replace('z', '☻')
new26_str = new25_str.replace(' ', 'f')
old_str = our_str[rounded:2 * rounded].replace('a', 'Y')
old1_str = old_str.replace('b', 'É')
old2_str = old1_str.replace('c', 'Θ')
old3_str = old2_str.replace('d', '╩')
old4_str = old3_str.replace('e', 'b')
old5_str = old4_str.replace('f', '█')
old6_str = old5_str.replace('g', '=')
old7_str = old6_str.replace('h', '↑')
old8_str = old7_str.replace('i', 'U')
old9_str = old8_str.replace('j', '⌂')
old10_str = old9_str.replace('k', '┬')
old11_str = old10_str.replace('l', 'æ')
old12_str = old11_str.replace('m', '◄')
old13_str = old12_str.replace('n', '1')
old14_str = old13_str.replace('o', 'B')
old15_str = old14_str.replace('p', 'Ñ')
old16_str = old15_str.replace('q', '╡')
old17_str = old16_str.replace('r', '▌')
old18_str = old17_str.replace('s', '♣')
old19_str = old18_str.replace('t', 'Γ')
old20_str = old19_str.replace('u', 'τ')
old21_str = old20_str.replace('v', '╔')
old22_str = old21_str.replace('w', '░')
old23_str = old22_str.replace('x', '┘')
old24_str = old23_str.replace('y', 'ó')
old25_str = old24_str.replace('z', ';')
old26_str = old25_str.replace(' ', 'ß')
get_str = our_str[3 * rounded:].replace('a', 'ç')
get1_str = get_str.replace('b', '1')
get2_str = get1_str.replace('c', '♣')
get3_str = get2_str.replace('d', 'ⁿ')
get4_str = get3_str.replace('e', '♠')
get5_str = get4_str.replace('f', 'S')
get6_str = get5_str.replace('g', '°')
get7_str = get6_str.replace('h', '♫')
get8_str = get7_str.replace('i', 'D')
get9_str = get8_str.replace('j', '│')
get10_str = get9_str.replace('k', '←')
get11_str = get10_str.replace('l', 'ƒ')
get12_str = get11_str.replace('m', 'Æ')
get13_str = get12_str.replace('n', 'P')
get14_str = get13_str.replace('o', '#') #skipped 0781, 6406
get15_str = get14_str.replace('p', '.') #0899
get16_str = get15_str.replace('q', '┤') #0348
get17_str = get16_str.replace('r', 'µ')
get18_str = get17_str.replace('s', 'E')
get19_str = get19_str.replace('t', '§')
get20_str = get20_str.replace('u', '▬')
get21_str = get21_str.replace('v', 'û')
get22_str = get22_str.replace('w', '♀')
get23_str = get23_str.replace('x', '&')
get24_str = get24_str.replace('y', '≈')
get25_str = get25_str.replace('z', 'ª') #4460
get26_str = get26_str.replace(' ', 'N')
tag_str = our_str[2 * rounded: 3 * rounded].replace('a', '╬')
tag1_str = tag_str.replace('b', '↓')
tag2_str = tag1_str.replace('c', '<')
tag3_str = tag2_str.replace('d', '╦')
tag4_str = tag3_str.replace('e', '-')
tag5_str = tag4_str.replace('f', 'δ') #skipped 360
tag6_str = tag5_str.replace('g', '▼')
tag7_str = tag6_str.replace('h', '╫')
tag8_str = tag7_str.replace('i', '`')
tag9_str = tag8_str.replace('j', 'û')
tag10_str = tag9_str.replace('k', '±')
tag11_str = tag10_str.replace('l', '⌡')
tag12_str = tag11_str.replace('m', '≈')
tag13_str = tag12_str.replace('n', ']')
tag14_str = tag13_str.replace('o', '╗')
tag15_str = tag14_str.replace('p', '┐')
tag16_str = tag15_str.replace('q', '>')
tag17_str = tag16_str.replace('r', '╞')
tag18_str = tag17_str.replace('s', '╟') #627
tag19_str = tag18_str.replace('t', '╘')
tag20_str = tag19_str.replace('u', 'L')
tag21_str = tag20_str.replace('v', 'v') #353
tag22_str = tag21_str.replace('w', '#')
tag23_str = tag22_str.replace('x', 'R')
tag24_str = tag23_str.replace('y', ';')
tag25_str = tag24_str.replace('z', '~')
tag26_str = tag25_str.replace(' ', '▓')
print(new26_str + old26_str + tag26_str + get26_str)
hi = input("Bye")
P.S - The hi input is to not let the Python console close.
1st Error: You have used variables in following statements without initializing them first
get19_str = get19_str.replace('t', '§')
get20_str = get20_str.replace('u', '▬')
get21_str = get21_str.replace('v', 'û')
get22_str = get22_str.replace('w', '♀')
get23_str = get23_str.replace('x', '&')
get24_str = get24_str.replace('y', '≈')
get25_str = get25_str.replace('z', 'ª') #4460
get26_str = get26_str.replace(' ', 'N')
2nd Error: If statements do not allow two relational operations to be performed on a single variable without using a logical operator for joining the two (in case of n relational operations you should use n-1 logical operators to combine them all)
Eg. Check if integer a is greater than 2 and less than 5
if (a>2) and (a<5):
#statements
So you will have to change your elif statement by seperating the two re
Try this:
elif ((rand > 2) and (rand <= 4)):
# Do your stuff here
Doing what you did will compare 2 to the expression (rand <= 4), which compares to a boolean, or 0/1.
The very first line: our_str = input("Mornin' ")
our_str should be converted to integer.
Your conditionals are not right.
elif 2 < rand <= 4: it doesn't work this way.
instead use elif rand in [3,4]: or elif rand > 2 and rand <= 4:
There are other errors as well, you can check the console and remove all the errors.
like you are using get19_str without even initialising it and so on...

Categories

Resources