python - Can someone help me I always get TypeError:Can't multiply sequence by non-int of type 'str'
问题描述
I am still new at python and I can't seem to get my code right. I was trying to have a FCFS that can calculate the waiting time and turn around time
def findWaitingTime(processes, n, bt, wt, at):
service_time = [0] * n
service_time[0] = 0
wt[0] = 0
for i in range(1, n):
service_time[i] = (service_time[i - 1] + bt[i - 1])
wt[i] = service_time[i] - at[i]
if (wt[i] < 0):
wt[i] = 0
def findTurnAroundTime(processes, n, bt, wt, tat):
for i in range(n):
tat[i] = bt[i] + wt[i]
def findavgTime(processes, n, bt, at):
wt = [0] * n
tat = [0] * n
findWaitingTime(processes, n, bt, wt, at)
findTurnAroundTime(processes, n, bt, wt, tat)
print("Processes Burst Time Arrival Time Waiting",
"Time Turn-Around Time Completion Time \n")
total_wt = 0
total_tat = 0
for i in range(n):
total_wt = total_wt + wt[i]
total_tat = total_tat + tat[i]
compl_time = tat[i] + at[i]
print(" ", i + 1, "\t\t", bt[i], "\t\t", at[i],
"\t\t", wt[i], "\t\t ", tat[i], "\t\t ", compl_time)
print("Average waiting time = %.5f "%(total_wt /n))
print("\nAverage turn around time = ", total_tat / n)
This is my main code where the user will input all the values:
if __name__ =="__main__":
n = int(input('Enter the total numbers of processes: '))
for i in range(n):
processes = input('Enter the processes: ')
for i in range(n):
burst_time = (int(input('Enter the burst time: ')))
for i in range(n):
arrival_time = (int(input('Enter the arrival time: ')))
findavgTime(n, processes, burst_time,arrival_time)
解决方案
推荐阅读
- ios - 谷歌分析,统一。iOS模拟器不发送事件
- angularjs - AngularJS,用于 Bootstrap 4 的 UIB,找不到和加载模板
- cookies - MS Edge 丢弃 cookie
- jmeter - 新手,需要帮助在 jmeter 中为并发 API 调用设计测试计划
- pandas - 如何使用 groupby 根据列的分位数值过滤数据框行?
- python - 如何通过使用 pandas read_html 引用特定的 HTML 类或 id 将网页数据拉入我的 DataFrame?
- c++ - 如何将可变参数 teamplate 中的值传递给原始指针?
- html - 我找不到将文本移动到 DIV 中间的方法
- drupal - Drupal 8 Twig 页面字段
- php - 如何在资源/访问受限的共享主机上使用 ffmpeg 和 laravel 5.7